Last active
November 29, 2016 15:49
-
-
Save jewzaam/d3e2a8331093ebf86aa43771bd0bb32b to your computer and use it in GitHub Desktop.
Self reference on array contents. Note the reference in the metadata may be wrong. This doesn't work yet, so the exact query hasn't been worked out yet.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"objectType": "selfReferenceArrayContainsArray", | |
"projection": [ | |
{ | |
"field": "*", | |
"include": true, | |
"recursive": true | |
},{ | |
"field": "test_reference", | |
"include": true, | |
"recursive": true | |
} | |
], | |
"query": { | |
"field": "objectType", | |
"op": "=", | |
"rvalue": "selfReferenceArrayContainsArray" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"entityInfo": { | |
"datastore": { | |
"backend": "mongo", | |
"collection": "selfReferenceArrayContainsArray", | |
"datasource": "mongodata" | |
}, | |
"defaultVersion": "0.0.1-SNAPSHOT", | |
"name": "selfReferenceArrayContainsArray" | |
}, | |
"schema": { | |
"access": { | |
"delete": [ | |
"anyone" | |
], | |
"find": [ | |
"anyone" | |
], | |
"insert": [ | |
"anyone" | |
], | |
"update": [ | |
"anyone" | |
] | |
}, | |
"fields": { | |
"_id": { | |
"type": "string", | |
"constraints": { | |
"identity": true | |
} | |
}, | |
"a": { | |
"type": "array", | |
"items": { | |
"type": "string" | |
} | |
}, | |
"expectation": { | |
"type": "string" | |
}, | |
"test_reference": { | |
"entity": "selfReferenceArrayContainsArray", | |
"query": { | |
"$and": [ | |
{ | |
"field": "_id", | |
"op": "$neq", | |
"rfield": "$parent._id" | |
}, | |
{ | |
"field": "a", | |
"op": "$neq", | |
"rvalue": null | |
}, | |
{ | |
"$not": { | |
"array": "a", | |
"elemMatch": { | |
"field": "$this", | |
"op": "$nin", | |
"rfield": "$parent.$parent.a" | |
} | |
} | |
} | |
] | |
}, | |
"type": "reference" | |
} | |
}, | |
"name": "selfReferenceArrayContainsArray", | |
"status": { | |
"value": "active" | |
}, | |
"version": { | |
"changelog": "selfReferenceArrayContainsArray", | |
"value": "0.0.1-SNAPSHOT" | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"upsert": true, | |
"data": [{ | |
"_id": "Q", | |
"expectation": "test_reference {selfReferenceArrayContainsArray.a $in [a,b,c]} returns: S, T", | |
"a": ["a","b","c"] | |
},{ | |
"_id": "R", | |
"expectation": "test_reference {selfReferenceArrayContainsArray.a $in [d,b,c]} returns: S, T", | |
"a": ["d","b","c"] | |
},{ | |
"_id": "S", | |
"expectation": "test_reference {selfReferenceArrayContainsArray.a $in [b,c]} returns: T", | |
"a": ["b","c"] | |
},{ | |
"_id": "T", | |
"expectation": "test_reference {selfReferenceArrayContainsArray.a $in [c]} returns: null", | |
"a": ["c"] | |
}] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The expectations don't match the query. array elemMatch query result will be true if the condition is true for at least one element of the array. Your expectations imply that you want it to be true for all array elements.