Ios swift queries with arrays containing objects

n1ql

#1

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?


#2

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.


#3

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?


#4

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.


#5

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?


#6

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.


#7

up to now, the dollar sign worked in Expression.property(). 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?


#8

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.


#9

just in a where statement (no join):
.and(ArrayExpression.any(ArrayExpression.variable(“a”)).in(Expression.property(“b.c”))
.satisfies(ArrayExpression.variable(“a.$oid”).equalTo(Expression.string(“191230923acd12”)))))

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


#10

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?


#11
{
     "labels" : {
        "values" : [ 
            "$oid": "56c20025533f4c14e4000799",
            "$oid": "56c20027533f4c14e40007af"
       ]
     }
}

#12

yes you can replace as proposed.


#13

Ok I filed this ticket based on this information.