Skip to content

Instantly share code, notes, and snippets.

@jewzaam
Last active November 29, 2016 15:49
Show Gist options
  • Save jewzaam/d3e2a8331093ebf86aa43771bd0bb32b to your computer and use it in GitHub Desktop.
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.
{
"objectType": "selfReferenceArrayContainsArray",
"projection": [
{
"field": "*",
"include": true,
"recursive": true
},{
"field": "test_reference",
"include": true,
"recursive": true
}
],
"query": {
"field": "objectType",
"op": "=",
"rvalue": "selfReferenceArrayContainsArray"
}
}
{
"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"
}
}
}
{
"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