mongoose如何查找某个数组里含有某个值?

例如

const ProjectSchema = new mongoose.Schema({

name : { type:String },time : { type:Date, default:Date.now },url : { type: String},user : { type: Object},proId : {type: String},spaceId : {type: String},description: {type: String},participant: {type: Array}

})

我需要 通过 传入的id 查找,participant里面含有该id的数据


眼眸繁星
浏览 6180回答 1
1回答

Qyouu

mongooes我不怎么熟,所以我就写查询语句了我不知道你的participant内部是什么结构假如是participant:[1,2,3]然后要找id是1,那么查询条件是{participant:{$elemMatch:{$eq:1}}}假如是participant:[{id:1,num:5}]然后要找id是1,那么查询条件是{participant:{$elemMatch:{id:1}}}$elemMatch
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

MongoDB