mongodb - Query Group Keys with Count in Different Collections -


i trying group set of key values found in different collections. need result value , count each of collections. divisionname chicago in both first collection , second collection.

another wrench in can have 15 submitted.submittedforms collections. issue output not combine values. 2 separate lines chicago instance. 1 each collection total count after 2 lines.

"submittedforms" : {     "submittedforms" : {         "0" : {             "fullname" : "john smith",             "emailaddress" : "'testmail@att.net",             "phonenumber" : "(555) 555-5555",             "marketid" : luuid("24c111da-bc1c-b14c-8ee9-a4e9d25d4a91"),             "comments" : "please send me more information                                    ",             "emailsent" : "1",             "internalemailsent" : "0",             "submittedtime" : isodate("2017-04-27t15:10:17.507z"),             "divisionname" : "columbus",             "communityname" : "test ridge",             "producttype" : "test"         },         "1" : {             "fullname" : "john smith",             "emailaddress" : "'testmail@att.net",             "phonenumber" : "(555) 555-5555",             "marketid" : luuid("67c503da-bc1c-b14c-8ee9-a4e9d25d4a91"),             "comments" : "please send me more information                                    ",             "emailsent" : "1",             "internalemailsent" : "0",             "submittedtime" : isodate("2017-04-27t15:10:17.507z"),             "divisionname" : "austin",             "communityname" : "test ridge",             "producttype" : "test product"         },         "2" : {             "fullname" : "john smith",             "emailaddress" : "'testmail@att.net",             "phonenumber" : "(555) 555-5555",             "marketid" : luuid("adfadsf-bc1c-b14c-8ee9-a4e9d25d4a91"),             "comments" : "please send me more information                                    ",             "emailsent" : "1",             "internalemailsent" : "0",             "submittedtime" : isodate("2017-04-27t15:10:17.507z"),             "divisionname" : "austin",             "communityname" : "the village",             "producttype" : "test"         },         "3" : {             "fullname" : "john smith",             "emailaddress" : "'testmail@att.net",             "phonenumber" : "(555) 555-5555",             "marketid" : luuid("y4444-bc1c-b14c-8ee9-a4e9d25d4a91"),             "comments" : "please send me more information                                    ",             "emailsent" : "1",             "internalemailsent" : "0",             "submittedtime" : isodate("2017-04-27t15:10:17.507z"),             "divisionname" : "columbus",             "communityname" : "test case",             "producttype" : "test"         }     } }, 

this need see: chicago 23 atlanta 12 new york 14

this tried do:

db.contacts.group({ "key": { "submittedforms.submittedforms.0.divisionname": {"submittedforms.submittedforms.0.divisionname":1,$exists:true,$ne:null,$where: "this.name.length > 0"}, "submittedforms.submittedforms.1.divisionname": {"submittedforms.submittedforms.1.divisionname":1,$exists:true,$ne:null,$where: "this.name.length > 0"} }, "initial": { "countdivision": 0 }, "reduce": function(obj, prev) {   if (true != null) if (true instanceof array) prev.countstar += true.length;     else prev.countdivision++; }, "cond": {     _id: {         "$ne": ["/testing.com/i"]     },     "submittedforms.submittedforms.0.submittedtime": {         "$gte": new isodate("2017-08-12 07:47:00z")     } } }); 

this current structure , submitted forms live.


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -