猫鼬多重嵌套选择

Mongoose multiple nested select

本文关键字:嵌套 选择      更新时间:2023-09-26

我正在尝试使用多个嵌套选择器对大型查询进行选择,例如:

 .select('parent.0.item parent.0.item2 other item');
但是,父数组中的第二个元素永远不会被选中,只返回第一个元素。有什么建议吗?

发现我必须简单地删除'。

.select('parent.item parent.item2 other item');

在Mongoose version 4中,您不需要像下面所示那样使用select()

   yourModel.find({}, 'parent.item parent.item2 other item',
     function (err, docs) {
    });
好运