aggregation framework - MongoDB query on count of elements in one of the subdocument array -
this question has answer here:
- how sort array inside collection record in mongodb 13 answers
- mongodb: combine data multiple collections one..how? 8 answers
- mongo order length of array 2 answers
given: documents looks this:
supplier document
{ "_id" : "63", "companyname" : "niranjan company", "createdby" : "niranjank4523@gmail.com", "createdon" : isodate("2017-07-06t03:12:13.171z"), "active" : true, "locations" : [ "594fbfc9ae0638325796a17c", "594fbfc9ae0638325796a17d", "594fbfc9ae0638325796a17e" ], "servicearea" : "nationwide", }, "updateddate" : isodate("2017-07-24t06:29:42.221z") }
locations document
{ "_id" : objectid("594fbfc9ae0638325796a17c"), "location" : "new york" }
requirement: sort collection in below manner
- supplier documents sorted number of locations.
- locations alphbetically sorted.
- supplier no locations appear @ end.
though able sort number of locations in it, still unable resolve second point of requirement in have furthur sort data alphabetically on basis of location , put suppliers without locations @ end.
note: can not change structure due constraints client.
Comments
Post a Comment