I am working with a database 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
}
}
]
});
The above code is used to query for specific documents
Chats.countDocuments(
{
members: {
$in: ["userIdOne", "userIdTwo"]
}
},
cb
)
In the code snippet, I am using $in
operator to filter data, but it retrieves all documents containing either one of the specified userId.... I actually need to retrieve only one document that contains both user ids.
Is there a way to achieve this?