0
{
data: [9, 3, 56, 3, 54]
}
{
data: [6, 3, 5, 3, 5]
}    
{

    data: [1, 2, 3, 4, 5]

    }

How do I get the only object which has 1 in the data array in MongoDB?

db.findOne({"data":1 in data})

Is that it?

0

1 Answer 1

1

Just use

db.collection.findOne({"data":1})

This matches all documents where 1 is in the array. See documentation.

Note that you (obviously) need to specify the collection.

BTW, this is pure Mongo shell, not pymongo. In pymongo, you'd write

db.collection.find_one({"data":1})
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.