$all parameter in mongodb does not work with ObjectId list
Asked Answered
T

1

0

I retrieve a list of ObjectId and I want to retrieve all object in my mongo database using the parameter $all

I'm using pymongo and my request look like this :

db.database.collection.find({ "_id" : { "$all" : [ObjectId('4ee371837c93dd33dc000003'),ObjectId('4eef9f647c93dd1a90000000')] } })

but the cursor count returned by the request is 0 but when I do this request:

db.database.collection.find_one({ "_id" : ObjectId('4ee371837c93dd33dc000003')})

It returns me the good object

Anyone know why it does not work?

Tesstessa answered 2/4, 2012 at 13:36 Comment(0)
P
8

That query does not make sense. You are asking for the unique and single-valued _id field to have all of two distinct values at the same time.

I think you want $in:

db.database.collection.find({ "_id" : { 
   "$in" : 
     [ObjectId('4ee371837c93dd33dc000003'),
      ObjectId('4eef9f647c93dd1a90000000')] } })
Poulson answered 2/4, 2012 at 13:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.