aggregation framework - MongoDB query on count of elements in one of the subdocument array -


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

  1. supplier documents sorted number of locations.
  2. locations alphbetically sorted.
  3. 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

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -