How to export sorted data using mongoexport?

前端 未结 3 2206
傲寒
傲寒 2021-02-07 08:53

I have a collection in mongo which has name and count fields.

{name:\'myName\',count:5}

Is it possible to sort data by count and export as json

3条回答
  •  情话喂你
    2021-02-07 09:27

    Starting with MongoDB 2.6, you can pass --sort to mongoexport directly:

    mongoexport --db mydatabase -c people --fields name,age --sort "{name: 1, age: 1}"
    

提交回复
热议问题