In meteor let's say I have a minimongo collection with the following documents:
{ "_id" : 1, "item" : "abc1", description: "ball", qty: 300 }
{ "_id" : 2, "item" : "abc2", description: "shoe", qty: 100 }
{ "_id" : 3, "item" : "xyz1", description: "tops", qty: 250 }
{ "_id" : 4, "item" : "VWZ1", description: "glue", qty: 300 }
{ "_id" : 5, "item" : "VWZ2", description: "glue", qty: 180 }
{ "_id" : 6, "item" : "XXX1", description: "shoe", qty: 500 }
and I want to use the $or operator to return the documents that either have qty > 250
or the description is shoe
.
result: { $or: [ { $gt: [ "$qty", 250 ] }, { $in: [ "$description", "shoe" ] } ] }
How can I make it so that the returned cursor is sorted in the following order:
- document(s) that have both
qty > 250
and description matchingshoe
- documents(s) that have just the description
shoe
- documents(s) that have just
qty > 250
Searching around it seems like a aggregations ref 1, ref 2 might be one option except for the fact that minimongo for meteor does not seems to appear to support aggregations at this point.
If this cannot be accomplished with a minimongo sort specifier/query etc, how would one alternatively sort the results as described above (assuming that it is done on the array/object returned from doing a fetch on the cursor)