Ios swift queries with arrays containing objects



object is as follows:
“labels” : {
“values” : [
{"$oid": “1234”},
{"$oid": “1235”},
{"$oid": “1236”},
{"$oid": “1237”}

can’t get an Expression (and Join) to be in a where clause to match a specific id (N1QL seems to have many primitives to do that, but these are not available currently in 2.1.1 ios swift bindings.

Any suggestion?


Please be more specific about what you are asking. Mobile does not have the equivalent to everything in N1QL so the feature you are after may not be available but it is unclear, at least to me, what you are after.


in the example above, “values” is an array of {"$oid": “1234”}, {"$oid": “1235”}. If I want to do a where Expression.string(“1235”) is present in this array, I can’t find how to do it with 2.1.1 swift ios release. The in does not seem to go inside the array. It appears that I would need some kind of aggregate/nesting functions available in normal N1QL queries, but not yet exposed/available in the swift ios bindings. Clearer?


Check out this blog which discusses examples of querying array elements. There is one similar to the case you have. Here is the corresponding playground. Specifically look into the Array expression.


Can't get it right. Would it be possible that the $ in the ArrayExpression.variable("value.$oid") statement would cause a problem in the underlying SQLite? the $ seems to have a special meaning for SQLite as I can see. Could it be passed through and SQLite does not like it?


If it doesn’t with SQLite, the Couchbase Lite actually gives a special meaning to this character so it would be best to avoid it if possible. I raised the issue internally and a fix is being developed (or has been, I can’t remember) so hopefully it won’t be an issue in the future.


up to now, the dollar sign worked in The source of the JSON is from MongoDB who uses the { $oid: “hexid” } form for any id in various nested places. Therefore, it is very complicated to avoid it. Should I fill a bug somewhere?


If it works in property then I’d expect it to work elsewhere too (looks like that fix already went in). Perhaps post the join you are attempting to use.


just in a where statement (no join):

my take is that ArrayExpression.variable is the issue, while is ok with “d.$oid”.


Could you also post an example of the document you are running this on? Can I replace “b.c” with “labels.values” in the above example?

     "labels" : {
        "values" : [ 
            "$oid": "56c20025533f4c14e4000799",
            "$oid": "56c20027533f4c14e40007af"


yes you can replace as proposed.


Ok I filed this ticket based on this information.