2

I want to search documents from the query console based on some property which is not null. Lets say this is the json documents i have.

{ "a1" : "1234", "a2" : "abc", "a3" : null, "a4" : "mno" }

{ "a1" : "1235", "a2" : "xyz", "a3" : "value", "a4" : "mno" }

I can query documents based on property like this

cts:search(fn:collection(), cts:json-property-value-query("a3","value"));

I am not able to use not equal logical operator with this query. Can anybody let me know, if i have to search documents based on property a3 which is not null then what has to be the query ?

1 Answer 1

3

Using just value-queries, I would do it like this:

cts:search(fn:collection(), cts:and-query(
            (
            cts:json-property-value-query("a3", "*", "wildcarded"),
            cts:not-query(cts:json-property-value-query("a3", json:null()))
            )
           ) 
      );

I could have affected this with a smaller query by using a word-query instead of a value query.

Note that the use of the wildcarded query was just to isolate candidate documents that had the element 'a3'. For XML, I would have used an element-query to make sure I had the element, but I do not know of any way to do that in json directly.

Sign up to request clarification or add additional context in comments.

2 Comments

What would the equivalent of this query using ServerSide JavaScript?
I do not have that answer - but I would think Query builder should be able to build the above. Note: This is a new question and will be lost in the comments. I suggest you open a new ticket and ask the question there.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.