Closed esrose closed 4 years ago
Hi @esrose! First of all, thank you for the bug report!
Now you cannot use $and
with a single selector, we will work on the fix.
Till then, you can use QueryBuilder builder = new QueryBuilder(eq("userId", "myUser"))
on your single element selectors. E.g.:
if (selectorArray.length == 1) {
new QueryBuilder(selectorArray[0])
} else {
new QueryBuilder(and(selectorArray))
}
Bug Description
When I instantiate a QueryBuilder with an and Operation containing only a single Selector, the resulting JSON does not have an array for the $and field inside the selector.
I'm an IBM Cloudant customer.
1. Steps to reproduce and the simplest code sample possible to demonstrate the issue
QueryBuilder builder = new QueryBuilder(and(eq("userId", "myUser")));
database.query(builder.build(), JsonObject.class);
Alternatively, inspect the
selector
variable on the QueryBuilder after step 1 to see the incorrect JSON. For example,"$and": {"userId": {"$eq": "myUser"}}
2. What you expected to happen
I expect QueryBuilder to emit JSON which is accepted by CouchDB, meaning $and should always be an array regardless of how many elements are in it.
3. What actually happened
CouchDB gives me a 400 error from the _find endpoint because the $and is malformed.
Environment details
I'm executing the query against CouchDB 3 in my local dev environment.