I have a list of ID's and I want to query a collection based on that list. The field I'm filtering is id_, it is an ObjectID.
Example:
list = ['abcd','mnop','qrst']
I want to search documents that the _id is in that list:
cursor = db.find( {"_id": { "$in": list} } )
cursor = db.find( {"_id": { "$in": ObjectId(list)} } )
I tried both options above and none of them worked.
The first one returned empty, and the second one throws a type error:
TypeError: id must be an instance of (bytes, str, ObjectId), not <class 'list'>
How can I correct my code?
ObjectIds:[ ObjectId('61bde475a216f8027c1379d1'), ...]list = [ObjectId(x) for x in list]. Thanks. Feel free to awnser the question