我有以下Order模型集合:
{
"_id" : ObjectId("5b5852483a3e8a0d00bb7fef"),
"items" : [
{
"_id" : ObjectId("5b5852483a3e8a0d00bb7ff3"),
"status" : "reserved"
},
{
"_id" : ObjectId("5b5852483a3e8a0d00bb7ff2"),
"status" : "remove"
},
{
"_id" : ObjectId("5b5852483a3e8a0d00bb7ff1"),
"status" : "reserved"
},
{
"_id" : ObjectId("5b5852483a3e8a0d00bb7ff0"),
"status" : "remove"
}
],
"status" : "reserved",
}
{
"_id" : ObjectId("5b5852483a3e8a0d00bb7fef"),
"items" : [
{
"_id" : ObjectId("5b5852483a3e8a0d00bb7ff3"),
"status" : "reserved"
},
{
"_id" : ObjectId("5b5852483a3e8a0d00bb7ff0"),
"status" : "reserved"
}
],
"status" : "reserved",
}
{
"_id" : ObjectId("5b5852483a3e8a0d00bb7fef"),
"items" : [
{
"_id" : ObjectId("5b5852483a3e8a0d00bb7ff3"),
"status" : "buy"
},
{
"_id" : ObjectId("5b5852483a3e8a0d00bb7ff0"),
"status" : "reserved"
}
],
"status" : "reserved",
}
{
"_id" : ObjectId("5b5852483a3e8a0d00bb7fef"),
"items" : [
{
"_id" : ObjectId("5b5852483a3e8a0d00bb7ff3"),
"status" : "reserved"
},
{
"_id" : ObjectId("5b5852483a3e8a0d00bb7ff0"),
"status" : "remove"
}
],
"status" : "reserved",
}
{
"_id" : ObjectId("5b5852483a3e8a0d00bb7fef"),
"items" : [
{
"_id" : ObjectId("5b5852483a3e8a0d00bb7ff3"),
"status" : "arrival"
},
{
"_id" : ObjectId("5b5852483a3e8a0d00bb7ff0"),
"status" : "reserved"
}
],
"status" : "reserved",
}
{
"_id" : ObjectId("5b5852483a3e8a0d00bb7fef"),
"items" : [
{
"_id" : ObjectId("5b5852483a3e8a0d00bb7ff3"),
"status" : "remove"
},
{
"_id" : ObjectId("5b5852483a3e8a0d00bb7ff0"),
"status" : "remove"
}
],
"status" : "reserved",
}
{
"_id" : ObjectId("5b5852483a3e8a0d00bb7fef"),
"items" : [
{
"_id" : ObjectId("5b5852483a3e8a0d00bb7ff0"),
"status" : "remove"
}
],
"status" : "reserved",
}
我想在子文档的 all 具有等于status
的{{1}}属性时恢复所有文档,但是如果它等于reserved
没问题,所以当我运行查询时,我必须得到:
remove
我当前的查询是:
{
"_id" : ObjectId("5b5852483a3e8a0d00bb7fef"),
"items" : [
{
"_id" : ObjectId("5b5852483a3e8a0d00bb7ff3"),
"status" : "reserved"
},
{
"_id" : ObjectId("5b5852483a3e8a0d00bb7ff2"),
"status" : "remove"
},
{
"_id" : ObjectId("5b5852483a3e8a0d00bb7ff1"),
"status" : "reserved"
},
{
"_id" : ObjectId("5b5852483a3e8a0d00bb7ff0"),
"status" : "remove"
}
],
"status" : "reserved",
}
{
"_id" : ObjectId("5b5852483a3e8a0d00bb7fef"),
"items" : [
{
"_id" : ObjectId("5b5852483a3e8a0d00bb7ff3"),
"status" : "reserved"
},
{
"_id" : ObjectId("5b5852483a3e8a0d00bb7ff0"),
"status" : "reserved"
}
],
"status" : "reserved",
}
{
"_id" : ObjectId("5b5852483a3e8a0d00bb7fef"),
"items" : [
{
"_id" : ObjectId("5b5852483a3e8a0d00bb7ff3"),
"status" : "reserved"
},
{
"_id" : ObjectId("5b5852483a3e8a0d00bb7ff0"),
"status" : "remove"
}
],
"status" : "reserved",
}
当所有嵌入文档的Order.find( { items: { $not: { $elemMatch: {status:{$ne: 'reserved' } }} } } )
属性都等于status
时检索文档。
任何帮助将不胜感激!