2014년 12월 27일 토요일

Mongo dump and get last id

I'm trying to implement a simple incremental backup with mongo dump.

Is there a convenient way to get the 'latest id' of the dumped result, 
or do i have to do the query again, sort it by id descendingly and limit by 1 ?



You mean get the _id of the last document that was dumped by mongodump? Or get the highest _id dumped by mongodump? The latter seems more interesting. Neither one would necessarily be possible to get from the mongod once the dump is complete - those documents could have been deleted. If you have a static collection during mongodump, then the largest _id dumped would be the result of db.collection.find().sort({ "_id" : -1}).limit(1) run when mongodump terminates, but in a changing collection there's no guarantee that this would work. To find the highest _id dumped you'd have to restore the dump and run the same query on the restored collection.

Most incremental approaches to MongoDB backup, like [MMS backup](http://docs.mongodb.org/manual/core/backups/#mongodb-management-service-mms-cloud-backup), use the [oplog](http://docs.mongodb.org/manual/core/replica-set-oplog/) to record changes to a collection and do point-in-time restores.



Yes it's the highest _id dumped by mongod.
Luckily that in my case i'm dumping a non-changing collection.
Thank you for the clarification !


댓글 없음:

댓글 쓰기