亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

nosql - MongoDB 如何獲取某條記錄的相鄰記錄
PHPz
PHPz 2017-04-21 10:56:25
0
1
761

比如獲取某篇文章的前一篇和后一篇記錄,有時(shí)間字段created

嘗試使用下列語(yǔ)句獲取文章

# created 是當(dāng)前文章的創(chuàng)建時(shí)間
# 前一篇
prev_post = db.Post.find({ 'created': { '$lt': created } }, sort = [('created', -1)], limit = 1)
# 后一篇
next_post = db.Post.find({ 'created': { '$gt': created } }, sort = [('created', 1)], limit = 1)

運(yùn)行的結(jié)果是這些記錄是跳躍使的,有時(shí)候中間會(huì)跳過(guò)好幾條記錄,不知道如何解決這個(gè)問(wèn)題
我想可能是我對(duì) find 的理解有誤,希望大家指點(diǎn)迷津

PHPz
PHPz

學(xué)習(xí)是最好的投資!

reply all(1)
黃舟

First of all, there is no problem with the statement, but you used the time type.
If the time type is used, it is likely that the time records are the same. Check whether your records have the same time.
If conditions permit, you can use _id或者配合_id to avoid this situation.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template