猫鼬查询具有不同值的相同字段 [英] mongoose query same field with different values
问题描述
是否可以使用用户 mongoose.find({title:'some title'})
来查询具有多个值的同一字段?例如,类似这样的 mongoose.find({title:'some title',title:'some other title'})
只发回匹配 title:'some other title
的文档>有没有办法做到这一点?
Is there a way to user mongoose.find({title:'some title'})
to query the same field with multiple values? For example something like this mongoose.find({title:'some title', title:'some other title'})
sends back only documents matching title:'some other title
is there a way to accomplish this ?
推荐答案
您应使用MongoDB $ in
运算符-
You should use the MongoDB $in
operator -
mongoose.find({title: {$in: ['some title', 'some other title']}})
您向 $ in
运算符提供一个数组,它将返回所有在指定数组中具有确切标题的文档.
You provide an array to $in
operator and it will return all the documents which have an exact title in the array specified.
这篇关于猫鼬查询具有不同值的相同字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!