MongoDb: Sort and store in a new collection -
i have collection patient documents not sorted. can sort using -
db.patient.find().sort({patient_id:1,admit_date:-1})
but want store sorted documents in new collection called patient2.
you can use $out
operator of aggregation framework output results new collection:
db.patient.aggregate([ {$sort:{patient_id:1,admit_date:-1}}, {$out:"patient2"} ])
Comments
Post a Comment