{
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?
{
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?
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})