Pymongo游标限制(1)返回1个以上的结果

sky*_*ler 11 python mongodb pymongo

这些是我的收藏中的所有文件:

{
    "_id" : ObjectId("5110291e6ee1c31d5b275d01"),
    "d" : 24,
    "s" : [
        1,
        2,
        3
    ]
}
{
    "_id" : ObjectId("511029266ee1c31d5b275d02"),
    "d" : 24,
    "s" : [
        4,
        5,
        6
    ]
}
{
    "_id" : ObjectId("5110292e6ee1c31d5b275d03"),
    "d" : 24,
    "s" : [
        7,
        8
    ]
}
Run Code Online (Sandbox Code Playgroud)

这个我要运行的查询:

mongo = get_collection(self.collection_name)
res = mongo.find().sort([('_id', -1)]).skip(1).limit(1)
Run Code Online (Sandbox Code Playgroud)

get_collection()是我制作的辅助方法.迭代游标,res只生成一个文档:

res = mongo.find().sort([('_id', -1)]).skip(1).limit(1)
for document in res:
    print document

> {u's': [4.0, 5.0, 6.0], u'_id': ObjectId('511029266ee1c31d5b275d02'), u'd': 24.0}
Run Code Online (Sandbox Code Playgroud)

但是,使用偏移量访问res会为第0个和第1个元素返回两个不同的文档:

res = mongo.find().sort([('_id', -1)]).skip(1).limit(1)
pprint(res[0])
> {u'_id': ObjectId('511029266ee1c31d5b275d02'), u'd': 24.0, u's': [4.0, 5.0, 6.0]}
pprint(res[1])
> {u'_id': ObjectId('5110291e6ee1c31d5b275d01'), u'd': 24.0, u's': [1.0, 2.0, 3.0]}
Run Code Online (Sandbox Code Playgroud)

这是一个错误吗?limit(1)应该只返回一个结果,不是吗?

sch*_*mar 13

文件说,这大约光标索引访问:

之前应用于此游标的任何限制都将被忽略.