Marklogic|NodeJS API - 查询特定类别 "properties"
Marklogic|NodeJS API - Query on a specific categorie "properties"
我的数据库中有一个 json 文档,如下所示:
{
"uri" : "/me/myself/and/bd1e0f91656bfc713eb6560eeaad7ad1.json",
"category" : "content",
"format" : "json",
"versionId" : "14697362595356370",
"contentType" : "application/json",
"contentLength" : "1938",
"collections" : ["http://me.myself.com/collectionA"],
"properties" : {
"relatives" : ["/me/myself/and/B.json", "/me/myself/and/A.json"]
},
"content":{}
}
我正在尝试获取属性中具有特定亲属的所有文档:
qb.where(
qb.scope(
qb.property('relatives'),
qb.word("/me/myself/and/B.json"),
qb.fragmentScope('properties')
))
但我不断收到大量不符合查询条件的文档。
知道如何使用 Marklogic NodeJS API 做到这一点吗?
我看到两件事看起来可能是问题。第一个是 qb.fragmentScope('properties')
。这告诉 MarkLogic 查看 document's properties,而不是文档的内容。鉴于您的示例 JSON 文档,这看起来不像您的意思。
第二个问题是单词查询——“/me/myself/and/B.json”很可能被分解成它的构成词(me、myself、and、B、json ), 然后在其他文档中匹配。您想要准确匹配那里的内容,因此请尝试值查询:
qb.where(
qb.scope(
qb.properties('properties'),
qb.value('relatives', '/me/myself/and/B.json')
)
)
请注意,qb.scope
和 qb.properties
将搜索限制为仅匹配出现在 relatives
中 properties
[=24= 下的值] 属性。这与上面提出的 JSON 属性-versus-content 点不同。
qb.where(
qb.propertiesFragment(
qb.term('/me/myself/and/B.json')
)
)
这对我有用。
我的数据库中有一个 json 文档,如下所示:
{
"uri" : "/me/myself/and/bd1e0f91656bfc713eb6560eeaad7ad1.json",
"category" : "content",
"format" : "json",
"versionId" : "14697362595356370",
"contentType" : "application/json",
"contentLength" : "1938",
"collections" : ["http://me.myself.com/collectionA"],
"properties" : {
"relatives" : ["/me/myself/and/B.json", "/me/myself/and/A.json"]
},
"content":{}
}
我正在尝试获取属性中具有特定亲属的所有文档:
qb.where(
qb.scope(
qb.property('relatives'),
qb.word("/me/myself/and/B.json"),
qb.fragmentScope('properties')
))
但我不断收到大量不符合查询条件的文档。
知道如何使用 Marklogic NodeJS API 做到这一点吗?
我看到两件事看起来可能是问题。第一个是 qb.fragmentScope('properties')
。这告诉 MarkLogic 查看 document's properties,而不是文档的内容。鉴于您的示例 JSON 文档,这看起来不像您的意思。
第二个问题是单词查询——“/me/myself/and/B.json”很可能被分解成它的构成词(me、myself、and、B、json ), 然后在其他文档中匹配。您想要准确匹配那里的内容,因此请尝试值查询:
qb.where(
qb.scope(
qb.properties('properties'),
qb.value('relatives', '/me/myself/and/B.json')
)
)
请注意,qb.scope
和 qb.properties
将搜索限制为仅匹配出现在 relatives
中 properties
[=24= 下的值] 属性。这与上面提出的 JSON 属性-versus-content 点不同。
qb.where(
qb.propertiesFragment(
qb.term('/me/myself/and/B.json')
)
)
这对我有用。