I'm using ML8. I have a bunch of json documents in the database. Some documents have a certain property "summaryData", something like:
{
...(other stuff)...
summaryData: {
count: 100,
total: 10000,
summaryDate: (date value)
}
}
However, not all documents have this property. I'd like to construct an SJS query to retrieve those documents that don't have this property defined. If it was SQL, I guess the equivalent would be something like "WHERE summaryData IS NULL"
I wasn't sure what to search for in the docs. Any advise would be helpful.
If you enjoyed my content for some reason, I'd love to hear from you! Here are some options:
- You can buy me a coffee!
- Click here to post a comment!
- You can write a reply on your own site and submit the URL as a webmention via the form below.
- Or you can just contact me!
You can find the existence of a JSON property in a document by using cts.jsonPropertyScopeQuery() and the second parameter set to cts.trueQuery()
To find the opposite, you can wrap that part of your query in
cts.notQuery()
Example:
Example inside of a larger query for clarity (or more confusion.. who knows.. :)
This is somewhat explained in the cts.elementQuery() documentation.
Lastly: one may argue that this is a duplicate of https://stackoverflow.com/questions/46076264/need-xquery-syntax-for-if-exists-behaviour-in-search-api I was going to mark it as a duplicate, but did not because you asked about SJS, a property and to negate the search. Someone else may differ in opinion and mark it as duplicate.