Reputation: 178
I want to construct a search query in javascript where I pass one document's URI and it's collections names so that I can get the document as output(JSON).
I tried fn.doc, cts.doc etc but I cannot find how to use collection name in it.
Upvotes: 2
Views: 318
Reputation: 4912
The URI should be sufficient to get the document. If you want to do it as a query, use cts.documentQuery(uri). If you want to ensure that it also has specific collections you can and in cts.collectionQuery(collections), something like:
cts.andQuery([cts.collectionQuery(collections),cts.documentQuery(uri)])
Upvotes: 3
Reputation: 2192
You might not need a complicated cts query for this:
let collections = xdmp.documentGetCollections('test.json')
if(collections.includes('test')) {
fn.doc('test.json')
} else {
"not found"
}
Just read the documents collections with xdmp.documentGetCollections
and test if it contains your collection. After that return it with fn.doc
.
Upvotes: 1