简体   繁体   中英

mongodb findMany by id in all records in array

I need to get from the database objects from each element in the array files, by array of ids ["c5f2d584-60ab-4068-b567-9b422f6c4e24","09c0ef39-55ea-45b4-88d3-a8f97730d6d3"] .

How to make such a request?

在此处输入图片说明

model.find({
    files: '_id' : ["c5f2d584-60ab-4068-b567-9b422f6c4e24","09c0ef39-55ea-45b4-88d3-a8f97730d6d3"]
}).
then(res => {
    console.log(res)
});

You can use the $in operator like this:

model.find({
    "files._id": { $in: ["c5f2d584-60ab-4068-b567-9b422f6c4e24","09c0ef39-55ea-45b4-88d3-a8f97730d6d3"] }
}).
then(res => {
    console.log(res)
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM