{
roomid: "",
questions: {
q1: {
user1:""
}
}
}
is there a way to query the document that match the roomid and match user1?
{
roomid: "",
questions: {
q1: {
user1:""
}
}
}
is there a way to query the document that match the roomid and match user1?
Hello @Allen_He,
To query with multiple conditions you use an $and logical operator. Your query can be formed as:
db.collection.find(
{ $and: [ { roomid: "" }, { "questions.q1.user1": "" } ] }
)
Note that you can also use the query filter as follows - without specifying the $and
operator. The results will be same:
{ roomid: "" , { "questions.q1.user1": "" }
This is because:
MongoDB provides an implicit
AND
operation when specifying a comma separated list of expressions.