javascript - 有没有办法将索引数组传递给 mongodb 并从该索引处的数组中获取元素
问题描述
我有一个包含 100 个元素的数组的 mongodb 文档,我想在查询数组中给定的索引处从该数组中获取多个元素。示例:让查询 = [2,3,5,6,7,4,44,32,71]; 所以,我想在查询数组中给出的索引处获取 mongodb doc 中数组中的元素。
解决方案
If you want filter data on mongo side, you can do like this.
db.getCollection('feed').find({
"_id" : {
"$in" : [
ObjectId("55880c251df42d0466919268"),
ObjectId("55bf528e69b70ae79be35006")
]
}
});
If not,
const filteredResult = items.filter(item => query.includes(item._id));
console.log(filteredResult);
推荐阅读
- python - 烧瓶错误:安装 Superset 时没有这样的命令“fab”
- python - How to use/convert sed to Python?
- python - jupyter 中无法识别 scipy 的版本
- rust - 两个 .await(在同一个异步块或函数中)是否并行执行?
- python - 创建一个脚本列表 tikinter 小部件
- filemaker - 选择下拉列表值时从数据库中选择数据。文件制作器
- javascript - laravel 当我在函数中使用参数时,视图模板会丢失
- c - '选项 « --color=auto » 未被识别
- azure - 无法使用 docker login 登录 ACR
- laravel - Laravel 雄辩的搜索功能