selectvsfind和在哪里find在Mongoose

在Mongoose文档中有这个小片段:

Person .find({ occupation: /host/ }) .where('name.last').equals('Ghost') .where('age').gt(17).lt(66) .where('likes').in(['vaporizing', 'talking']) .limit(10) .sort('-occupation') .select('name occupation') .exec(callback); 

我很难理解.find({ occupation: /host/ }).select('name occupation') .find({ occupation: /host/ })不同的.select('name occupation') 。 是否find像在哪里添加条件? 还是它控制返回的字段? 更新好了,所以我看到select只控制查询的最终结果的字段,但现在我不明白如何FindWhere是不同的。 我不能使用Find和使用Where创build相同的查询? 下面的代码片段是一样的吗?

 Person .where('occupation').equals('host') .where('name.last').equals('Ghost') .where('age').gt(17).lt(66) .where('likes').in(['vaporizing', 'talking']) .limit(10) .sort('-occupation') .select('name occupation') .exec(callback); 

find是实际的查询。 在这个例子中,你得到的所有行的occupation等于host 。 现在,每个匹配该查询的对象都有几个属性。 让我们假设它有属性nameageemailoccupation 。 当你指定你想select nameoccupation你说你只是想要这些属性。 所以在我们的情况下, ageemail将不会从查询发回。

在这种情况下用于指定多个查询的约束条件。 通常, where使用,因为它比提供更大的灵活性,比如在javascriptexpression式中传递

select的API文档 :

查询argarg

指定要包含或排除的文档字段

.select('name occupation')表示结果应该只包含nameoccupation领域。 您不希望在结果中看到其他字段。

find描述哪些文件包含在结果中。 select指示这些文档的哪些字段应该在结果中可见。