lightblue-platform/lightblue-mongo

Still not able to do self-association on array field

Closed this issue · 2 comments

I've setup this example and it's still not working as expected.

https://gist.github.com/jewzaam/d3e2a8331093ebf86aa43771bd0bb32b

The query I am running:

{
    "objectType": "selfReferenceArrayContainsArray",
    "projection": [
        {
            "field": "*",
            "include": true,
            "recursive": true
        },{
            "field": "test_reference",
            "include": true,
            "recursive": false
        }
    ],
    "query": {
    	"field": "objectType",
    	"op": "$eq",
    	"rvalue": "selfReferenceArrayContainsArray"
    }
}

The result I'm getting is that every object has every other object in the projected test_reference association. It shouldn't be everything. It isn't clear in the explain plan what is going on, the association query has null and [] (empty array) noted for the rhs of the query.

{
  "status": "COMPLETE",
  "modifiedCount": 0,
  "matchCount": 1,
  "processed": [
    {
      "project": [
        {
          "field": "*",
          "include": true,
          "recursive": true
        },
        {
          "field": "test_reference2",
          "include": true,
          "recursive": false
        }
      ],
      "source": {
        "assemble": {
          "entity": "selfReferenceArrayContainsArray",
          "left": {
            "entity": "selfReferenceArrayContainsArray",
            "search": {
              "field": "objectType",
              "op": "$eq",
              "rvalue": "selfReferenceArrayContainsArray"
            },
            "projection": [
              {
                "field": "a#",
                "include": true,
                "recursive": false
              },
              {
                "field": "_id",
                "include": true,
                "recursive": false
              },
              {
                "field": "a.*",
                "include": true,
                "recursive": false
              },
              {
                "field": "expectation",
                "include": true,
                "recursive": false
              },
              {
                "field": "objectType",
                "include": true,
                "recursive": false
              }
            ],
            "implementation": {
              "request": {
                "query": {
                  "field": "objectType",
                  "op": "$eq",
                  "rvalue": "selfReferenceArrayContainsArray"
                },
                "projection": [
                  {
                    "field": "a#",
                    "include": true,
                    "recursive": false
                  },
                  {
                    "field": "_id",
                    "include": true,
                    "recursive": false
                  },
                  {
                    "field": "a.*",
                    "include": true,
                    "recursive": false
                  },
                  {
                    "field": "expectation",
                    "include": true,
                    "recursive": false
                  },
                  {
                    "field": "objectType",
                    "include": true,
                    "recursive": false
                  }
                ]
              },
              "mongo": {
                "query": {
                  "$and": [
                    {
                      "objectType": "selfReferenceArrayContainsArray"
                    },
                    {
                      "objectType": "selfReferenceArrayContainsArray"
                    }
                  ]
                },
                "projection": {
                  "a": 1,
                  "a#": 1,
                  "_id": 1,
                  "expectation": 1,
                  "objectType": 1
                },
                "plan": {
                  "queryPlanner": {
                    "plannerVersion": 1,
                    "namespace": "data.selfReferenceArrayContainsArray",
                    "indexFilterSet": false,
                    "parsedQuery": {
                      "$and": {
                        "0": {
                          "objectType": {
                            "$eq": "selfReferenceArrayContainsArray"
                          }
                        },
                        "1": {
                          "objectType": {
                            "$eq": "selfReferenceArrayContainsArray"
                          }
                        }
                      }
                    },
                    "winningPlan": {
                      "stage": "PROJECTION",
                      "transformBy": {
                        "a": 1,
                        "a#": 1,
                        "_id": 1,
                        "expectation": 1,
                        "objectType": 1
                      },
                      "inputStage": {
                        "stage": "COLLSCAN",
                        "filter": {
                          "$and": {
                            "0": {
                              "objectType": {
                                "$eq": "selfReferenceArrayContainsArray"
                              }
                            },
                            "1": {
                              "objectType": {
                                "$eq": "selfReferenceArrayContainsArray"
                              }
                            }
                          }
                        },
                        "direction": "forward"
                      }
                    },
                    "rejectedPlans": {}
                  },
                  "executionStats": {
                    "executionSuccess": true,
                    "nReturned": 4,
                    "executionTimeMillis": 0,
                    "totalKeysExamined": 0,
                    "totalDocsExamined": 4,
                    "executionStages": {
                      "stage": "PROJECTION",
                      "nReturned": 4,
                      "executionTimeMillisEstimate": 0,
                      "works": 6,
                      "advanced": 4,
                      "needTime": 1,
                      "needYield": 0,
                      "saveState": 0,
                      "restoreState": 0,
                      "isEOF": 1,
                      "invalidates": 0,
                      "transformBy": {
                        "a": 1,
                        "a#": 1,
                        "_id": 1,
                        "expectation": 1,
                        "objectType": 1
                      },
                      "inputStage": {
                        "stage": "COLLSCAN",
                        "filter": {
                          "$and": {
                            "0": {
                              "objectType": {
                                "$eq": "selfReferenceArrayContainsArray"
                              }
                            },
                            "1": {
                              "objectType": {
                                "$eq": "selfReferenceArrayContainsArray"
                              }
                            }
                          }
                        },
                        "nReturned": 4,
                        "executionTimeMillisEstimate": 0,
                        "works": 6,
                        "advanced": 4,
                        "needTime": 1,
                        "needYield": 0,
                        "saveState": 0,
                        "restoreState": 0,
                        "isEOF": 1,
                        "invalidates": 0,
                        "direction": "forward",
                        "docsExamined": 4
                      }
                    },
                    "allPlansExecution": {}
                  },
                  "serverInfo": {
                    "host": "lightbluemongo...",
                    "port": 27017,
                    "version": "3.2.4",
                    "gitVersion": "e2ee9ffcf9f5a94fad76802e28cc978718bb7a30"
                  },
                  "ok": 1
                }
              }
            }
          },
          "right": [
            {
              "associationQuery": {
                "$and": [
                  {
                    "field": "_id",
                    "op": "$neq",
                    "rvalue": null
                  },
                  {
                    "array": "a",
                    "elemMatch": {
                      "field": "$this",
                      "op": "$in",
                      "values": []
                    }
                  }
                ]
              },
              "source": {
                "assemble": {
                  "entity": "selfReferenceArrayContainsArray",
                  "left": {
                    "entity": "selfReferenceArrayContainsArray",
                    "search": null,
                    "projection": [
                      {
                        "field": "a#",
                        "include": true,
                        "recursive": false
                      },
                      {
                        "field": "_id",
                        "include": true,
                        "recursive": false
                      },
                      {
                        "field": "a.*",
                        "include": true,
                        "recursive": false
                      },
                      {
                        "field": "expectation",
                        "include": true,
                        "recursive": false
                      },
                      {
                        "field": "objectType",
                        "include": true,
                        "recursive": false
                      }
                    ],
                    "implementation": {
                      "request": {
                        "projection": [
                          {
                            "field": "a#",
                            "include": true,
                            "recursive": false
                          },
                          {
                            "field": "_id",
                            "include": true,
                            "recursive": false
                          },
                          {
                            "field": "a.*",
                            "include": true,
                            "recursive": false
                          },
                          {
                            "field": "expectation",
                            "include": true,
                            "recursive": false
                          },
                          {
                            "field": "objectType",
                            "include": true,
                            "recursive": false
                          }
                        ]
                      },
                      "mongo": {
                        "query": {
                          "objectType": "selfReferenceArrayContainsArray"
                        },
                        "projection": {
                          "a": 1,
                          "a#": 1,
                          "_id": 1,
                          "expectation": 1,
                          "objectType": 1
                        },
                        "plan": {
                          "queryPlanner": {
                            "plannerVersion": 1,
                            "namespace": "data.selfReferenceArrayContainsArray",
                            "indexFilterSet": false,
                            "parsedQuery": {
                              "objectType": {
                                "$eq": "selfReferenceArrayContainsArray"
                              }
                            },
                            "winningPlan": {
                              "stage": "PROJECTION",
                              "transformBy": {
                                "a": 1,
                                "a#": 1,
                                "_id": 1,
                                "expectation": 1,
                                "objectType": 1
                              },
                              "inputStage": {
                                "stage": "COLLSCAN",
                                "filter": {
                                  "objectType": {
                                    "$eq": "selfReferenceArrayContainsArray"
                                  }
                                },
                                "direction": "forward"
                              }
                            },
                            "rejectedPlans": {}
                          },
                          "executionStats": {
                            "executionSuccess": true,
                            "nReturned": 4,
                            "executionTimeMillis": 0,
                            "totalKeysExamined": 0,
                            "totalDocsExamined": 4,
                            "executionStages": {
                              "stage": "PROJECTION",
                              "nReturned": 4,
                              "executionTimeMillisEstimate": 0,
                              "works": 6,
                              "advanced": 4,
                              "needTime": 1,
                              "needYield": 0,
                              "saveState": 0,
                              "restoreState": 0,
                              "isEOF": 1,
                              "invalidates": 0,
                              "transformBy": {
                                "a": 1,
                                "a#": 1,
                                "_id": 1,
                                "expectation": 1,
                                "objectType": 1
                              },
                              "inputStage": {
                                "stage": "COLLSCAN",
                                "filter": {
                                  "objectType": {
                                    "$eq": "selfReferenceArrayContainsArray"
                                  }
                                },
                                "nReturned": 4,
                                "executionTimeMillisEstimate": 0,
                                "works": 6,
                                "advanced": 4,
                                "needTime": 1,
                                "needYield": 0,
                                "saveState": 0,
                                "restoreState": 0,
                                "isEOF": 1,
                                "invalidates": 0,
                                "direction": "forward",
                                "docsExamined": 4
                              }
                            },
                            "allPlansExecution": {}
                          },
                          "serverInfo": {
                            "host": "lightbluemongo...",
                            "port": 27017,
                            "version": "3.2.4",
                            "gitVersion": "e2ee9ffcf9f5a94fad76802e28cc978718bb7a30"
                          },
                          "ok": 1
                        }
                      }
                    }
                  },
                  "right": []
                }
              }
            }
          ]
        }
      }
    }
  ],
  "hostname": "lightbluecrud..."
}

I would like to see:

  1. verification that the gist is correct and expected result is valid
  2. unit test added using the gist to test this functionality

Perfect. That did it, thanks!