【发布时间】:2017-08-01 20:07:55
【问题描述】:
我在 Mongo 中有一个用户数据库。我想检索不在我被阻止的数组中的所有用户。试图通过检索所有文档来过滤结果,但我想知道这是否是最有效的方法。 Mongo 有没有办法找到不属于数组的所有用户?
这是我的用户模型:
var UserSchema = mongoose.Schema({
username: {
type: String,
index:true,
unique: true
},
password: {
type: String
},
email: {
type: String,
unique: true
},
name: {
type: String
},
latitude:{
type: String
},
longitude:{
type: String
},
blocked:{
type: Array
},
friends:{
type: Array
},
photo:{
type: String
},
identity:{
type: String
},
age:{
type: String
},
herefor:{
type: String
},
conns:{
type: Number
},
status:{
type: String
}
}, { collection: 'users' });
【问题讨论】:
-
不清楚你在问什么。您可能想要
$nin,但您还应该阅读所有query operators 的一般用途,并了解在哪里应用它们。 -
你试过$nin吗?