获取特定文档的下一个和上一个文档 [英] Getting next and previous document of a specific document
本文介绍了获取特定文档的下一个和上一个文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在mongoDB中,什么是仅使用 _id
来获取文档的下一个和上一个文档的最佳实践?
In mongoDB what is best practice to get the next and previous document of a document using just its _id
?
推荐答案
如果您要按创建顺序对文档进行排序,则可以按文档_id进行排序.
You can sort by document _id if you'd like to sequence the documents in order of creation.
即
db.mycollection.find().sort({_id:-1});
这篇关于获取特定文档的下一个和上一个文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文