如何获得某些条件的文件?

时间:2017-02-07 03:25:53

标签: mongodb match

我有一些对象:

var array = [];

var obj1 = new Object();
obj1.category = 0;
obj1.sequence = 0;
obj1.otherAttr = 1;
array.push(obj1)

var obj2 = new Object();
obj2.category = 1;
obj2.sequence = 2;
obj1.otherAttr = 2;
array.push(obj2)

var obj3 = new Object();
obj3.category = 4;
obj4.sequence = 3;
obj1.otherAttr = 3;
array.push(obj3)

...

我在MongoDB中有收集:

{
    category:0,
    sequence:0,
    anotherAttr:1
},
{
    category:0,
    sequence:1,
    anotherAttr:2
},
{
    category:0,
    sequence:2,
    anotherAttr:3
},
{
    category:1,
    sequence:0,
    anotherAttr:4
},
{
    category:1,
    sequence:1,
    anotherAttr:5
},
{
    category:1,
    sequence:2,
    anotherAttr:6
},
...

我想插入这些物品。但在插入这些内容之前,我希望检查MongoDB中与类别和序列之间的重叠序列与otherAttr或anotherAttr无关的文档。例如,我有像top这样的对象,我需要的结果是:

{
    category:0,
    sequence:0,
    anotherAttr:1
},
{
    category:1,
    sequence:1,
    anotherAttr:5
}

我试过$match。但无法检查许多属性中的某些条件。

0 个答案:

没有答案
相关问题