比如獲取某篇文章的前一篇和后一篇記錄,有時(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)迷津
學(xué)習(xí)是最好的投資!
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.