How to search with full match on the array?

There is a model
Schema({
 members: [
{
 type: String,
 required: true,
 ref: "User"
}
],
 createdAt: {
 type: Date,
 default: Date.now(),
 required: true
},
 lastMessage: {
 message: {
 type: String,
 required: true
},
 from: {
 type: String,
 required: true
},
 createdAt: {
 type: Date,
 required: true
}
},
 messages: [
{
 createdAt: {
 type: Date,
 required: true
},
 message: {
 type: String,
 required: true
},
 from: {
 type: String,
 ref: "User",
 required: true
}
}
]
});


Code like this I ispolzuu to search
Chats.countDocuments(
{
 members: {
 $in: ["userIdOne", "userIdTwo"]
}
},
cb
 )


The problem is that the search is not the full coincidence of the parameter $in. If multiple documents, where members will be at least one parameter is userId... of $in the search it will show.

I'll have if I asked two parameters print only those documents where there is only two of these parameters, that is, by complete coincidence.
April 8th 20 at 10:34
1 answer
April 8th 20 at 10:36
I found a solution.
You need to use $all instead of $in
Chats.countDocuments(
{
 members: {
 $all: ["userIdOne", "userIdTwo"]
}
},
cb
)

Find more questions by tags MongoDBMongoose