我有文件,像这样:
{
"_id" : ObjectId("5c763335eabaf70627249465"),
"permissions" : [
"adminCompany"
],
"city" : "890",
"companyName" : "qwe",
"country" : "890",
"county" : "890",
"email" : "varadi83gabor@gmail.com",
"headquarters" : null,
"modifyed" : null,
"name" : "qwe",
"nickname" : null,
"password" : "202cb962ac59075b964b07152d234b70",
"postalCode" : "890",
"registered" : ISODate("2019-02-27T06:50:29.035Z"),
"shops" : [
{
"_id" : ObjectId("5c797074b2e01c38ac55b796"),
"city" : "Nagymaros",
"country" : "Hungary",
"county" : "Pesyt",
"currency" : "HUF",
"district" : null,
"language" : null,
"name" : "Piknik",
"phone" : "123123123",
"places" : [
{
"_id" : ObjectId("5c79714fb2e01c2ee3196a63"),
"name" : "terasz",
"products" : [
{
"_id" : ObjectId("5c797162b2e01c2ee3196a65"),
"active" : true,
"added" : null,
"description" : "borocska baszod",
"modified" : null,
"name" : "bor",
"taxPercentage" : 27,
"unit" : "liter",
"unitPrice" : 1500
}
],
"qrcodes" : [
{
"_id" : ObjectId("5c79715cb2e01c2ee3196a64"),
"name" : "asztal1"
}
]
},
{
"_id" : ObjectId("5c79718cb2e01c52afb050f9"),
"name" : "emelet",
"products" : [
{
"_id" : ObjectId("5c79719db2e01c52afb050fb"),
"active" : true,
"added" : null,
"description" : "sorocske baszod",
"modified" : null,
"name" : "sor",
"taxPercentage" : 27,
"unit" : "korso",
"unitPrice" : 500
},
{
"_id" : ObjectId("5c7971deb2e01c52afb050fd"),
"active" : true,
"added" : null,
"description" : "szaros viz",
"modified" : null,
"name" : "teodora",
"taxPercentage" : 27,
"unit" : "liter",
"unitPrice" : 1000
}
],
"qrcodes" : [
{
"_id" : ObjectId("5c797195b2e01c52afb050fa"),
"name" : "qr1"
}
]
},
{
"_id" : ObjectId("5c7a20ef2fa7fa847633bb39"),
"name" : "Addf",
"products" : [],
"qrcodes" : [
{
"_id" : ObjectId("5c7a20f92fa7fa847633bb3a"),
"name" : "Kisfaszom"
}
]
}
],
"postalCode" : "123",
"region" : "Közép-Magyarország",
"staffs" : [
{
"permissions" : [
"staffServing"
],
"_id" : ObjectId("5c7a6248b2e01c744f8b67b5"),
"email" : "varadi83gabor@gmail.com",
"modifyed" : null,
"name" : "12e12e",
"nickname" : "qweqwe",
"password" : "202cb962ac59075b964b07152d234b70",
"registered" : ISODate("2019-03-02T11:00:25.956Z"),
"status" : "active"
},
{
"permissions" : [
"staffFront",
"staffCourier",
"staffManager",
"staffServing"
],
"_id" : ObjectId("5c7a629fb2e01c744f8b67b7"),
"email" : "varadi83gabor@gmail.com",
"modifyed" : null,
"name" : "Kis Ferenc",
"nickname" : "123123",
"password" : "202cb962ac59075b964b07152d234b70",
"registered" : ISODate("2019-03-02T11:01:52.235Z"),
"status" : "active"
}
],
"status" : "active",
"street" : "qewqweqwe",
"streetNumber" : 123123
},
{
"_id" : ObjectId("5c7aa611b2e01c5565f70aff"),
"city" : "Budapest",
"country" : "Hungary",
"county" : "pest",
"currency" : "HUF",
"district" : "VI. kerület",
"language" : null,
"name" : "Kiado kocsma",
"phone" : "123123",
"places" : [],
"postalCode" : "1066",
"region" : "Közép-Magyarország",
"staffs" : [],
"status" : "active",
"street" : "Jokai",
"streetNumber" : 19
}
],
"status" : "inactive",
"street" : "890",
"streetNumber" : "890",
"taxNumber" : "890",
"__v" : 0
}
this.companyManager.aggregate([
{"$match": {"shops.staffs._id": body.staffId}},
{"$unwind": "$shops"},
{"$unwind": "$shops.staffs"},
{"$match": {"shops.staffs._id": body.staffId}},
{"$project": {_id: "$shops.staffs._id", shops: "$shops", staff: "$staffs"}},
], function(error, result:Null<Array<Dynamic>>) {
trace(error);
trace(result);
if (result.length == 0) {
callback({status: Status.ERROR, data: result, error: "not found staff"});
} else {
callback({status: (error == null) ? Status.SUCCESS : Status.ERROR, data: result[0].staff, error: error});
}
});
{"staff":<staffData>,"shops":[shopsArray]}
{
"staff": {
"permissions": [
"staffServing"
],
"_id": ObjectId("5c7a6248b2e01c744f8b67b5"),
"email": "varadi83gabor@gmail.com",
"modifyed": null,
"name": "12e12e",
"nickname": "qweqwe",
"password": "202cb962ac59075b964b07152d234b70",
"registered": ISODate("2019-03-02T11:00:25.956Z"),
"status": "active"
},
"shops": [<SHOPS DOCUMENTS>]
}
我希望现在这是清楚的,谢谢!
试试这个
我使用了映射
和筛选
db.companyManager.aggregate([
{
'$addFields': {
'staff': {
'$filter': {
'input': {
'$map': {
'input': '$shops',
'as': 'shop',
'in': {
'staffs': {
'$filter': {
'input': '$$shop.staffs',
'as': 'staff',
'cond': {
'$eq': [
'$$staff._id', body.staffId
]
}
}
}
}
}
},
'as': 'staff',
'cond': {
'$gt': [
{
'$size': '$$staff.staffs'
}, 0
]
}
}
}
}
},
{$unwind: "$staff"},
{$project: {_id:0, staff: "$staff.staffs", shops: "$shops"} },
{$unwind: "$staff"}
])
问题内容: 我需要将父目录和其他子目录中的文件包含到子目录中。我之前只使用include(’/ rootdirectory / file.php’); 但现在看来似乎行不通。 只是想知道我该怎么做,谢谢。 这是我的确切行: 它给我这个错误(页面仍在运行): 警告: include(/forums/groups.php)[function.include]:无法打开流:C:\ xampp \ htd
给定一个场景,其中我有一个根文档和一个对象数组。是否可以返回包含一组对象的文档? 例如: 文件1 文件2 我需要一个查询,该查询将根据以下内容匹配并返回Doc1: 在数组中包含key1=value1的对象的文档 这可能吗?
问题内容: 我有以下模型: 我正在寻找一个查询,该查询检索不属于某个特定组的所有人员(即,人员的组数组不包含指定组的ID)。 我在考虑这样的事情,但是我不确定它是正确的: 问题答案: 基本的尝试没什么错,但是这里唯一的澄清可能是普遍的误解,即您需要像 或 查询数组时这样的运算符。 另外,您真的需要在这里做一个基本的不等式匹配 : “数组”运算符不用于“数组目标”,而是用于提供条件的“列表”以方便的
我实际上有两种类型的数据: 我想用Hamcrest在我的身体响应中测试我的放心请求后,b(元素接收)是否包含来自a的一个或多个元素(
问题内容: 我有一个与此类似的文件: 我要查询以查找所有包含“ a”的人(鲍勃和玛丽)。如何编写查询? 编辑: 当前查询: 问题答案: 在字段上使用术语过滤器/查询(例如)可以满足您的需求。假设您只想匹配满足该条件的任何文档,则完整查询将类似于: 之所以可行,是因为值数组是分别索引的,并且如果查询的字段是列表,则术语查询将查找包含包含该值的数组的文档。
我正在尝试查找不包含至少一个具有特定字段值的文档的所有文档。例如,下面是一个示例集合: 我希望找到docs块中没有包含至少一个foo=1的记录的文档的每个记录。在上面的示例中,应该只返回第二个文档。 我还查看了$nin运算符,但示例只显示数组包含基元值列表时的情况,而不是附加文档。当我尝试使用类似于下面的东西来实现这一点时,它查找的是确切的文档,而不仅仅是我想要的foo字段。 有没有用基本运算符来