0
votes

I've defined a path range index for a field and it might happen that the field value is null. The object stored in Marklogic is like:

{"the": {"path": {"to": {"field": null} } } }

I've tried the query

cts:path-range-query("/the/path/to/field", "=", json:null())

and it doesn't return any result. If, instead I define a new value for when the field is null and create an index just for this case, the search return results.

New document:

{"the": {"path": {"to": {"field": null, "fieldIsNull": true} } } }

New query:

cts:path-range-query("/the/path/to/fieldIsNull", "=", "true")

how can I search for null values using a path range index without resorting to a new index?

I'm using Marklogic 9.0-4.

2
@brunovianarezende-- When you say null values. By that you mean you want to return the nodes which are having empty values ?? - Shalini
no, I'm referring to values that are really null. I've updated the question to make it clear. - brunovianarezende
What is the datatype of your path index? xs:string? - grtjn
yes, it is a string. - brunovianarezende

2 Answers

0
votes

You can use something like this in Server-Side JavaScript:

cts.jsonPropertyValueQuery("field", null)

Which is written like this in XQuery:

cts:json-property-value-query("Output", null-node {})

Did you try replacing json:null() with null-node{} in your path range query?

HTH!

0
votes

In my view, this is where MarkLogic really blew it incorporating JSON. XQuery and XML don't have NULL values, and in fact nulls are a huge problem that one is blissfully free of when using XML and XQuery. But now not only do you have actual nulls, you have a NullNode type. Which gives you this anomalous behavior:

let b=null
b ? 'true' : 'false'  // returns false 

let a=new NullNode()
a ? 'true' : 'false'  // returns true

This makes it way more complicated to deal with data containing 'null,' as if that weren't a total hassle to begin with!