查找包含无限数量的属性,属性名称和属性值的对象

时间:2018-09-28 07:11:45

标签: node.js mongodb mongoose mongodb-query

具有猫鼬模式,该模式包含一个名为Object的名为“ attributes”的属性。

“属性”对象可以包含无限数量的属性,属性名称和属性值。

示例:

对象1:

attributes: {
    age: 21,
    nickName: ['The Mountain'],
    habits: ['football', 'rugby'],
    school: ['International School of Boston']
}

对象2:

attributes: {
    age: 25,
    numberOfCars: [3],
    favoriteCarBrands: ['Mercedes', 'Porsche', 'Ferrarri'],
    school: ['International School of Boston']
}

当包含值的属性存在并且值也存在时,我想找到这些对象。

例如,如果我有一个类似的对象,我想找到 Object1

{
    habits: ['football']
}

如果我有这样的对象,我想找到 Object1 Object2

{
    school: ['International School of Boston'],
}

如果我有这样的对象,我想找到 Object1

{
    school: ['International School of Boston'],
    age: 21
}

我的问题是,构造一个查询(或多个查询,如果需要的话)以执行这种查找操作的最佳方法是什么。

非常感谢

0 个答案:

没有答案