node.js - mongodb findMany by id 在数组中的所有记录中
问题描述
我需要通过 ids 数组从数组文件中的每个元素中获取数据库对象["c5f2d584-60ab-4068-b567-9b422f6c4e24","09c0ef39-55ea-45b4-88d3-a8f97730d6d3"]
。
如何提出这样的要求?
model.find({
files: '_id' : ["c5f2d584-60ab-4068-b567-9b422f6c4e24","09c0ef39-55ea-45b4-88d3-a8f97730d6d3"]
}).
then(res => {
console.log(res)
});
解决方案
您可以像这样使用 $in 运算符:
model.find({
"files._id": { $in: ["c5f2d584-60ab-4068-b567-9b422f6c4e24","09c0ef39-55ea-45b4-88d3-a8f97730d6d3"] }
}).
then(res => {
console.log(res)
});
推荐阅读
- python - Python:如何每次获取数组的下 k 个连续元素?
- visual-studio-2015 - 未生成 CMake 目标 RUN_TESTS
- android - 我有一个始终以固定大小显示的 TextView
- google-data-studio - 如何添加动态过滤数据的下拉控件?
- amazon-web-services - Terraform:如何在 concat 变量后添加子网掩码?
- c - 如何从文件中获取全名并将其与用户搜索的内容进行比较?
- python-3.x - 如何在处理其他代码时让 python 等待?
- oracle-apex - 用于将所选记录的列值更新为 sysdate 的按钮
- netsuite - 项目履行搜索工具包/包裹项目
- node.js - Node.js 有没有办法将时间戳转换为 .csv 文件中的日期?