【发布时间】:2019-06-29 18:31:36
【问题描述】:
这是我的收藏的架构:
{
_id: {
type: String,
required: true,
unique: true
},
translations: [{
language: String,
translation: String
}]
}
如果我有一个语言数组["spanish", "french"],我如何找到Collection.translations 没有数组中至少一种语言的对象的所有文档?
例如应该选择这个:
{
_id: "hello",
translations: [{
language: "not spanish",
translation: "not hola"
}]
}
但不是这些:
{
_id: "hello",
translations: [{
language: "spanish",
translation: "hola"
}]
}
//and
{
_id: "hello",
translations: [{
language: "spanish",
translation: "hola"
}, {
language: "french",
translation: "bonjour"
}, {
language: "not spanish",
translation: "not hola"
}]
}
这是我目前所拥有的:
Model.findOne({
translations: { $elemMatch: { language: ??? } }
});
【问题讨论】:
标签: arrays node.js mongodb mongoose