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?

Onedayanam
  • 95
  • 7

1 Answers1

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})
Jérôme
  • 13,328
  • 7
  • 56
  • 106