MONGO DB QUERY-组字段不在嵌套文档中-聚合

时间:2018-07-31 17:38:58

标签: mongodb nosql

{
  "_id": "Sh",
  "Name": "HR",
  "Form": [
    {
      "Name": "HR",
      "Permission": {

      },
      "Fields": [
        {
          "OutputFormat": "Text",
          "Validation": [

          ],
          "Name": "PASS",
          "Permission": {
            "Hidden": [
              "ac"
            ]
          },
          "IsFormulaArg": false,
          "MaxCharacters": 100.0,
          "Label": "PASS",
          "Widget": "Dropdown",
          "DefaultPermission": [

          ],
          "Dropdown": "me",
          "Score": 1,
          "PermissionType": "Hidden",
          "Id": "me"
        },
        {
          "OutputFormat": "dd/MM/yyyy",
          "NodeList": {
            "Score": 2,
            "Type": "CellReference",
            "Id": "jdk2",
            "Value": null,
            "CellMetadata": {
              "72uw": "CreatedAt"
            }
          },
          "Name": "Date_Prepared",
          "Permission": {

          },
          "IsFormulaArg": false,
          "Required": true,
          "Widget": "Date",
          "Label": "Date Prepared",
          "Score": 2,
          "FormulaStr": "CreatedAt",
          "Formula": "True",
          "DefaultPermission": [

          ],
          "Id": "7283"
        }
      ]
    }
  ]
} 

现在我必须将所有包含公式:“ TRUE”的文档归为一组

我写的查询是

aggregate(
[


{"$unwind":"$Form"},

{"$unwind":"$Form.Fields"},

{"$project":{"Form.Fields.Formula":{"$cond":{ if:{"$exits":"true"},
then:1,else: 0}}}},

{"$match":{"Form.Fields.Formula":0}},

我只是匹配具有“公式”字段的字段并尝试将它们分组

如果文档中没有“公式字段”,我应该排除。

我需要使用聚合函数对它们进行分组

0 个答案:

没有答案