Is it possible to mongodump the last “x” records from a collection?

前端 未结 6 654
感动是毒
感动是毒 2021-01-31 08:41

Can you use mongodump to dump the latest \"x\" documents from a collection? For example, in the mongo shell you can execute:

db.stats.find().sort({$natural:-1}).         


        
6条回答
  •  礼貌的吻别
    2021-01-31 09:16

    mongodump supports the --query operator. If you can specify your query as a json query, you should be able to do just that.

    If not, then your trick of running a query to dump the records into a temporary collection and then dumping that will work just fine. In this case, you could automate the dump using a shell script that calls a mongo with a javascript command to do what you want and then calling mongodump.

提交回复
热议问题