MarkLogic-查询未定义特定json属性的文档 [英] MarkLogic - query for documents where a specific json property is not defined

查看:78
本文介绍了MarkLogic-查询未定义特定json属性的文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用ML8.我在数据库中有一堆json文档.一些文档具有某些属性"summaryData",例如:

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)
  }
}

但是,并非所有文档都具有此属性.我想构造一个SJS查询来检索那些未定义此属性的文档.如果是SQL,我想它相当于"WHERE summaryData IS NULL"

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.

推荐答案

您可以使用 cts.jsonPropertyScopeQuery(),第二个参数设置为 cts.trueQuery( )

You can find the existence of a JSON property in a document by using cts.jsonPropertyScopeQuery() and the second parameter set to cts.trueQuery()

要找到相反的含义,可以将查询的那一部分包装在cts.notQuery()

To find the opposite, you can wrap that part of your query in cts.notQuery()

示例:

cts.search(
  cts.notQuery(
    cts.jsonPropertyScopeQuery('summaryData', cts.trueQuery())
  )
)

在更大的查询中为清楚起见(或更混乱的是..谁知道.. :)的示例

Example inside of a larger query for clarity (or more confusion.. who knows.. :)

cts.search(
  cts.andQuery([
     cts.directoryQuery('/some/scoping/path/'), 
     cts.notQuery(
        cts.jsonPropertyScopeQuery('myMissingElement', cts.trueQuery())
     )
 ])
)

cts.elementQuery()文档对此有所解释.

最后:有人可能会说这是,我打算将其标记为重复,但并不是因为您询问了SJS属性和否定搜索.其他人的观点可能会有所不同,并将其标记为重复.

Lastly: one may argue that this is a duplicate of 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.

这篇关于MarkLogic-查询未定义特定json属性的文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆