简体   繁体   English

MongoDB查找查询参数

[英]MongoDB find query params

I have a mongo query on a collection. 我对一个集合有一个mongo查询。 It looks like this: 它看起来像这样:

common.db.collection('vb.vbStats').find({uid:uid, "vbs.vbNID":vbNID}, {"vbs.$":1}).toArray(function(err, result) {....}

vb.vbstats is my collection. vb.vbstats是我的收藏。 vbs is a field of the collection that is an array of arrays of ducoments. vbs是集合的一个字段,是一个ducoments数组的数组。 My question is what does {"vbs.$":1} in the query. 我的问题是查询中的{"vbs.$":1}是什么。

{"vbs.$":1} is a query operation that uses the positional $ operator to limit the contents of the array vbs from the query results to contain only the first element matching the query document. {"vbs.$":1}是一个查询操作,它使用位置$运算符将查询结果中的数组vbs的内容限制为仅包含与查询文档匹配的第一个元素。

So in you example, the projection {"vbs.$": 1} returns only the first element in the array vbs which has vbNID = vbNID . 因此,在您的示例中,projection {"vbs.$": 1}仅返回数组vbs中具有vbNID = vbNID的第一个元素。 Refer to the docs for more details 有关更多详细信息,请参阅文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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