How do I query for nil values with CloudKit.js?

独自空忆成欢 提交于 2019-12-02 07:58:54

问题


Using CloudKit.js, how do I construct a query that matches items where a field is nil? Every permutation I've tried fails - either it's clearly matching on a string value (i.e. "null" or "nil") or it throws an error if I actually try to pass 'null'.

Any ideas? None of the below work.

filterBy: [{
        fieldName: 'customerNumber',
        comparator: 'EQUALS',
        fieldValue: { value: "nil" }
}]

filterBy: [{
        fieldName: 'customerNumber',
        comparator: 'EQUALS',
        fieldValue: { value: null }
}]

filterBy: [{
        fieldName: 'customerNumber',
        comparator: 'EQUALS',
        fieldValue: { value: "null" }
}]

filterBy: [{
        fieldName: 'customerNumber',
        comparator: 'EQUALS',
        fieldValue: { value: "" }
}]

回答1:


I don't think there is any option to query for nil values in CloudKit. Also not from native code. I have tried a lot of predicates, but non seems to work.

You do have to be aware that CloudKit is a key-value store. When a value is nil, then the key won't be there in the record. There is no option to query for non existing keys.

The closest I have come to a good solution was with a predicate with the format "NOT myField => ''" sorry, don't know the format for .js

In the CloudKit CKQuery documentation there is nothing mentioned about nil fields.

In the documentation for NSPredicates there are sample's for nil values.

But it was already clear that CloudKit has implemented only a subset of the possibilities of NSPredicate (see CKQuery class reference)

I think the best way to handle this is by not using/depending on nil values. If you do need to check some nil status, then instead you could add an extra field that would represent that status.



来源:https://stackoverflow.com/questions/32683691/how-do-i-query-for-nil-values-with-cloudkit-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!