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  }
})
2

1 Answer 1

0

You can try something like the below code.

db.users.find({ 
  username: keyword,
  _id: { $in: [usersId] }
})
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.