简体   繁体   中英

MongoDB find query params

I have a mongo query on a collection. 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. vbs is a field of the collection that is an array of arrays of ducoments. My question is what does {"vbs.$":1} in the query.

{"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.

So in you example, the projection {"vbs.$": 1} returns only the first element in the array vbs which has vbNID = vbNID . Refer to the docs for more details

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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