1

exp my collection users

[
    {
        _id: ObjectId('123456')
        username: 'test'
    },
    {
        _id: ObjectId('654321')
        username: 'test2'
    },
    {
        _id: ObjectId('789101')
        username: 'test3'
    }
]

my array available :

var usersId = [ObjectId('123456'), ObjectId('654321')]

i want find with field username and just in array usersId available

my test not working :

db.users.find({ 
  username: keyword,
  _id: { $in: usersId  }
})
Jubei Yagyu
  • 121
  • 2
  • 11

1 Answers1

0

You can try something like the below code.

db.users.find({ 
  username: keyword,
  _id: { $in: [usersId] }
})
Pushprajsinh Chudasama
  • 7,772
  • 4
  • 20
  • 43