2024-04-25 05:38:12 发布
网友
我正试图查询MongoDB,但查询的是_ids列表
_ids
例如:
db.test.find(ObjectId(['4ecc05e55dd98a436ddcc47c',4ecc05e55dd98a436adfc47c', ....] ))
申报你的名单:
list_of_ids = [ObjectId("4ecc05e55dd98a436ddcc47c"),ObjectId("4ecc05e55dd98a436adfc47c")]
然后运行db.test.find({'_id': {'$in': list(list_of_ids)}}
db.test.find({'_id': {'$in': list(list_of_ids)}}
您需要使用^{}运算符,例如
db.test.find({'_id': {'$in': [ObjectId("4ecc05e55dd98a436ddcc47c"), ObjectId("4ecc05e55dd98a436adfc47c")]}})
这在Mongo shell和pymongo中都有效
申报你的名单:
然后运行
db.test.find({'_id': {'$in': list(list_of_ids)}}
您需要使用^{} 运算符,例如
这在Mongo shell和pymongo中都有效
相关问题 更多 >
编程相关推荐