Still not able to do self-association on array field
Closed this issue · 2 comments
jewzaam commented
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:
- verification that the gist is correct and expected result is valid
- unit test added using the gist to test this functionality
bserdar commented
Expected result is not valid. The way reference query is written, every
object will include all others. Check my comment for the gist, pointing to:
https://github.com/bserdar/lightblue-core/blob/ec8449d36d0335251cceb8d586cd2bff4cd53b7b/crud/src/test/resources/composite/self_ref_array_not_contains.json
That is, use $not:{...$nin }
…On Mon, Nov 28, 2016 at 4:05 PM, Naveen Malik ***@***.***> wrote:
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": "lightbluemongo1.dev2.a1.vary.redhat.com",
"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": "lightbluemongo1.dev2.a1.vary.redhat.com",
"port": 27017,
"version": "3.2.4",
"gitVersion": "e2ee9ffcf9f5a94fad76802e28cc978718bb7a30"
},
"ok": 1
}
}
}
},
"right": []
}
}
}
]
}
}
}
],
"hostname": "lightbluecrud3.dev2.a1.vary.redhat.com"
}
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
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#339>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ADgDDbV9IvjHY4KSgBNW4kFQxDC45PFZks5rC15XgaJpZM4K-XsM>
.
jewzaam commented
Perfect. That did it, thanks!