Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 727 Vote(s) - 3.44 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do I perform an id array query in Mongoose?

#1
Let's say I have a model called `User`.
I have an array with object Ids.

I want to get all User records that "intersect" with the array of Ids that I have.

User.find({ records with IDS IN [3225, 623423, 6645345] }, function....
Reply

#2
User.where({ records: { $in: [3225, 623423, 6645345] } }, function ...
more info here:

[To see links please register here]

Reply

#3
Here is a mongoosey way to use the $in operator.

User.find()
.where('fb.id')
.in([3225, 623423, 6645345])
.exec(function (err, records) {
//make magic happen
});

I find the dot notation quite handy for querying into sub documents.

[To see links please register here]


Reply

#4
For me, work this way

IDs=["5b00c4b56c7fb80918293dd9","5b00c4b56c7fb80918293dd7",...]
const users= await User.find({records:IDs})
Reply

#5
You need to use the $in operator >

[To see links please register here]


For example:

Users.find( { "fb" : { id: { $in : arrayOfIds } } }, callback );
Reply

#6
Ids is the array of object ids:

const ids = [
'4ed3ede8844f0f351100000c',
'4ed3f117a844e0471100000d',
'4ed3f18132f50c491100000e',
];

With callback:

User.find().where('_id').in(ids).exec(callback);

With async function:

records = await User.find().where('_id').in(ids).exec();
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through