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

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -