Reputation: 3099
I have this example here and i'm trying to only query the empty mongodb array
var data = [{
"dynamic_env": null,
"mission_critical": null,
"chart-version": null,
"app-url": null,
"mongodb": {},
"nightly_shutdown": false,
"external_values": null,
"external_values_source": null,
"external_values_path": null,
"atlas_database": null,
"allow_db_restore": null,
"on-demand": false,
"helm_timeout": null,
"aws-account": null,
"post": [],
"pre": [],
"atlas_project": null,
"istio-enabled": false,
"env_subscription": null,
"istio-auth-policy": null,
"version": null,
"e2e-tests-script": [],
"morning_startup": true,
"project_dst": null,
"cred": null,
"dataset": null,
"project_src": null,
"Env": {
"identifier": "cm-infra-ci-core1@admin365-infra-stg-eks@admin365-cm-infra-ci-core1",
"title": "cm-infra-ci-core1"
},
"namespace": "admin365-cm-infra-ci-core1",
"cluster": {
"identifier": "admin365-infra-stg-eks@infra-stg",
"title": "admin365-infra-stg-eks"
},
"Service": {
"identifier": "user-data-management-gdpr-fetch",
"title": "user-data-management-gdpr-fetch"
},
"team": null,
"$identifier": "user-data-management-gdpr-fetch@cm-infra-ci-core1@admin365-cm-infra-ci-core1",
"$title": "user-data-management-gdpr-fetch@cm-infra-ci-core1"
},
{
"dynamic_env": null,
"mission_critical": null,
"chart-version": null,
"app-url": null,
"mongodb": {a: 123},
"nightly_shutdown": false,
"external_values": null,
"external_values_source": null,
"external_values_path": null,
"atlas_database": null,
"allow_db_restore": null,
"on-demand": false,
"helm_timeout": null,
"aws-account": null,
"post": [],
"pre": [],
"atlas_project": null,
"istio-enabled": false,
"env_subscription": null,
"istio-auth-policy": null,
"version": null,
"e2e-tests-script": [],
"morning_startup": true,
"project_dst": null,
"cred": null,
"dataset": null,
"project_src": null,
"Env": {
"identifier": "cm-infra-ci-core1@admin365-infra-stg-eks@admin365-cm-infra-ci-core1",
"title": "cm-infra-ci-core1"
},
"namespace": "admin365-cm-infra-ci-core1",
"cluster": {
"identifier": "admin365-infra-stg-eks@infra-stg",
"title": "admin365-infra-stg-eks"
},
"Service": {
"identifier": "user-data-management-gdpr-fetch",
"title": "user-data-management-gdpr-fetch"
},
"team": null,
"$identifier": "user-data-management-gdpr-fetch@cm-infra-ci-core1@admin365-cm-infra-ci-core1",
"$title": "user-data-management-gdpr-fetch@cm-infra-ci-core1"
}];
var res = alasql(`SELECT * FROM ? WHERE ('mongodb'->() = {})`,[data]);
console.log(res.length); // [{"a":1,"b":40},{"a":2,"b":20}]
Upvotes: 0
Views: 340
Reputation: 131
Add a user-defined function that returns the number of keys in the object, then query it:
alasql.fn.keylen = function(x) { return Object.keys(x).length; }
var res = alasql(`SELECT * FROM ? WHERE keylen(mongodb) = 0`,[data]);
Upvotes: 0