I have the following documents:
{ "_id" : 3, "quizzes" : [ 4, 5, 5 ], "labs" : [ 6, 5 ], "final" : 78, "midterm" : 70 }
{ "_id" : 1, "quizzes" : [ 4, 5, 5 ], "labs" : [ 6, 5 ], "midterm" : 70 }
If I run the following query:
db.students.aggregate([ { "$project": { "midterm": 1,"final": 1 } } ])
The result is as follows:
{ "_id" : 3, "final" : 78, "midterm" : 70 }
{ "_id" : 1, "midterm" : 70 }
If I change the order in the projection, still in the shell, do the fields go in the same order? can we restore the order on the basis of which it was requested?
db.students.aggregate([ { "$project": { "final":1, "midterm": 1 } } ])
{ "_id" : 3, "final" : 78, "midterm" : 70 }
{ "_id" : 1, "midterm" : 70 }
Use the case why order is important:
I have a collection that stores daily data for the user. If a user did some action on that day, there would be a field in the document for that user in this document. We keep this day for 200 days ... In yet another collection, we need to update when userFirstActive is in the last 200 days ...
. , - , ...
, 200 ... , id, . , ?