Dev_INX
(Dev Inx)
#1
*name is unique
collection : {
[{
_id: ‘1’,
name: “Bob”,
},
{
_id: ‘2’,
name: “sara”,
},
{
_id: ‘3’,
name: “jon”,
},
],
}
arrayToFind = [“Bob”,“sara”]
need to find all matching names in one call.
expected result => {
_id: ‘1’,
name: “Bob”,
},
{
_id: ‘2’,
name: “sara”,
},
steevej
(Steeve Juneau)
#2
Please enjoy the fine documentation of $in.
1 Like
Dev_INX
(Dev Inx)
#3
$in returns only one doc and not all of them
steevej
(Steeve Juneau)
#4
In does not. See the many examples in from the documentation.
Or this one:
mongosh> c.find()
{ _id: '1', name: 'Bob' }
{ _id: '2', name: 'sara' }
{ _id: '3', name: 'jon' }
mongosh> arrayToFind = [ "Bob" , "sara" ]
mongosh> c.find( { "name" : { "$in" : arrayToFind } } )
{ _id: '1', name: 'Bob' }
{ _id: '2', name: 'sara' }
1 Like
Dev_INX
(Dev Inx)
#5
thanks I find the bug in my code
1 Like
steevej
(Steeve Juneau)
#6
Please share so others do not fall on the same trap.
2 Likes