Pymong的运营商问题

2024-10-03 06:21:20 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图在python的pymongo模块中使用$in运算符。 我有一份身份证清单如下:

ids = [ObjectId('5a02ec6c3ae7b3225ed14ed0'), ObjectId('5a02ec6c3ae7b3225ed14ed2')]

下面是我的python代码:

client = connect_mongodb()
db = client.get_default_database()
societies = db['Societies']
result = societies.find({"_id":{"$in": ids}})
print result.count() #it prints 0 showing criteria didn't match`

但在mongo shell中,如果我触发以下查询:

db.getCollection('Societies').find({"_id" : {$in : [ ObjectId("5a02ec6c3ae7b3225ed14ed0") ,ObjectId("5a02ec6c3ae7b3225ed14ed2")]} })

它给了我两个结果。 我的python代码有什么问题?在


Tags: 模块代码inclientididsdb运算符