Mongoexport 版本 2.2.x 可以做到这一点——查询和排序。它不支持限制 - 版本 2.6 支持该选项。
查询作为 json 文档传递给 mongoexport:
- 询问
Provides a JSON document as a query that optionally limits the documents returned in the export.
您可以通过 $orderby 排序(未记录但这里有一个很好的讨论):
如何使用 mongoexport 导出排序数据?
和例子:
--query '{ $query: {}, $orderby: {count: -1} }'
直到 2.6 版才支持限制:
- 限制
Specifies a maximum number of documents to include in the export. See limit() for information about the underlying operation.
2.6 也有不同的排序语法:
- 种类
Specifies an ordering for exported results. If an index does not exist that can support the sort operation, the results must be less
超过 32 兆字节。
Use --sort conjunction with --skip and --limit to limit number of exported documents.
链接:
http://docs.mongodb.org/manual/reference/program/mongoexport/
http://docs.mongodb.org/v2.2/reference/mongoexport/