Is as simple as pass the values into find()
method with an $or
condition.
Check this example:
db.collection.find({
"$or": [
{
"username": {
"$regex": "testuser"
}
},
{
"email": {
"$regex": "testuser"
}
}
]
})
Return the values where username
or email
contains testuser
.
With mongoose
you can use the saeme:
yourModel.find({
"$or": [
{ "username": { "$regex":"testuser" } },
{"email": { "$regex":"testuser" } }
]
}).then(result => {
console.log(result);
}).catch(e => {
console.log(e);
})
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…