1

I have an array of user ids

Is it possible to query my database using the array as a parameter, returning all the user objects in the database that have the ids in my array?

This was my previous attempt

var array = ['123', '1234', '12345'];

            var query = PUser.find({'userID': array});
                                 query.exec(function(err, users_result) {
                                   if (!err) {
    console.log('all user objects with the array's IDs', users_result);
    }

1 Answer 1

8

The $in operator would do the trick.

var query = PUser.find({'userID': {$in:array}});
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.