sorting - Why does MongoDB sort return empty names for ascending sorted documents? -
i have simple collection of restaurants (from mongodb documentation). 1 of fields “name”. can find names of restaurants follows:
db.restaurants.find({}, {"name" : 1, "_id" : 0}); if try sort descending order, i.e.,
db.restaurants.find({}, {"name" : 1, "_id" : 0}).sort({"name":-1}); everything comes out fine:
{ "name" : "zz's pizza & grill" } { "name" : "zz clam bar" } ... however, if try sort ascending order:
db.restaurants.find({}, {"name" : 1, "_id" : 0}).sort({"name":1}); i get
{ "name" : "" } { "name" : "" } ... what's odd if add other keys sort argument before "name", ascending sort properly, i.e.
db.restaurants.find({}, {"name" : 1, "_id" : 0}).sort({"cuisine":1, "name":1}); what gives? insights!
Comments
Post a Comment