Reputation: 150
I have a mongoose
model:
let schema = new Schema({
email: {
type: String,
required: true,
unique: true
},
password: {
type: String
},
username: {
type: String,
unique: true
},
confirmed: {
type: Boolean
},
payload: [{
type: {
token: blablabla,
type: blablabla
}
}]
});
And i want find user by payload.token
. How can I do that? I tried $elemMatch
, but it does not work.
Upvotes: 0
Views: 523
Reputation: 3266
If payload
is an array of objects and you want to find users by token value , below query should work :
db.users.find({payload: {$elemMatch: {'type.token':'blablabla'}}});
Upvotes: 0