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

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -