How does mongoose find a value in an array?

for example

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}

})

I need to find it through the id passed in, and the participant contains the data of the id

Mar.28,2021

I'm not familiar with mongooes, so I wrote queries
I don't know what's inside your participant
if it's

participant:[1,2,3]

then look for id is 1, then the query condition is

{participant:{$elemMatch:{$eq:1}}}

if it is

 participant:[{id:1,num:5}]

then look for id is 1, then the query condition is

{participant:{$elemMatch:{id:1}}}

$elemMatch

Menu