简体   繁体   中英

Remove or Find an object with Mongoose when it is in an array by the object property value

This is what the data looks like for an entity called "Project"

{ systems:[ { systemId: 1234, count: 3 }, { systemId: 87642, count: 2 } ] }

What I want to is find in Projects collection all projects that have in systems an object with the systemId of 1234.

Please note that systems is an Array

你应该这样

Project.find({'systems':{$elemMatch:{'systemId':1234}}})

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