How to write java script lookup functions in marklogic?
I have three json documents in my database with their unique URI's.
/employee/100.json
{
"id": "100",
"name": "niranjan",
"status": "unprocessed"
}
/domain/100.json
{
"id": "100",
"domain": "java"
}
/salary/100.json
{
"id": "100",
"salary": "3000"
}
Now, I've to write a javascript lookup functions to fetch the details from corresponding documents based on "id" from /employee/100.json.
The output should look like this:
/final/100.json
{
"id": "100",
"name": "niranjan",
"domain": "java",
"salary": "3000"
}
How to do this??
marklogic marklogic-9
add a comment |
I have three json documents in my database with their unique URI's.
/employee/100.json
{
"id": "100",
"name": "niranjan",
"status": "unprocessed"
}
/domain/100.json
{
"id": "100",
"domain": "java"
}
/salary/100.json
{
"id": "100",
"salary": "3000"
}
Now, I've to write a javascript lookup functions to fetch the details from corresponding documents based on "id" from /employee/100.json.
The output should look like this:
/final/100.json
{
"id": "100",
"name": "niranjan",
"domain": "java",
"salary": "3000"
}
How to do this??
marklogic marklogic-9
can you post what you have tried so far ?
– Gaurav Rana
Jan 2 at 8:07
I haven't tried anything in javascript, but I was going through this stackoverflow.com/questions/10157616/marklogic-join-query
– Deepan Chelliah
Jan 2 at 11:02
add a comment |
I have three json documents in my database with their unique URI's.
/employee/100.json
{
"id": "100",
"name": "niranjan",
"status": "unprocessed"
}
/domain/100.json
{
"id": "100",
"domain": "java"
}
/salary/100.json
{
"id": "100",
"salary": "3000"
}
Now, I've to write a javascript lookup functions to fetch the details from corresponding documents based on "id" from /employee/100.json.
The output should look like this:
/final/100.json
{
"id": "100",
"name": "niranjan",
"domain": "java",
"salary": "3000"
}
How to do this??
marklogic marklogic-9
I have three json documents in my database with their unique URI's.
/employee/100.json
{
"id": "100",
"name": "niranjan",
"status": "unprocessed"
}
/domain/100.json
{
"id": "100",
"domain": "java"
}
/salary/100.json
{
"id": "100",
"salary": "3000"
}
Now, I've to write a javascript lookup functions to fetch the details from corresponding documents based on "id" from /employee/100.json.
The output should look like this:
/final/100.json
{
"id": "100",
"name": "niranjan",
"domain": "java",
"salary": "3000"
}
How to do this??
marklogic marklogic-9
marklogic marklogic-9
edited Jan 3 at 0:44
Dave Cassel
6,9841531
6,9841531
asked Jan 2 at 8:04
Deepan ChelliahDeepan Chelliah
325
325
can you post what you have tried so far ?
– Gaurav Rana
Jan 2 at 8:07
I haven't tried anything in javascript, but I was going through this stackoverflow.com/questions/10157616/marklogic-join-query
– Deepan Chelliah
Jan 2 at 11:02
add a comment |
can you post what you have tried so far ?
– Gaurav Rana
Jan 2 at 8:07
I haven't tried anything in javascript, but I was going through this stackoverflow.com/questions/10157616/marklogic-join-query
– Deepan Chelliah
Jan 2 at 11:02
can you post what you have tried so far ?
– Gaurav Rana
Jan 2 at 8:07
can you post what you have tried so far ?
– Gaurav Rana
Jan 2 at 8:07
I haven't tried anything in javascript, but I was going through this stackoverflow.com/questions/10157616/marklogic-join-query
– Deepan Chelliah
Jan 2 at 11:02
I haven't tried anything in javascript, but I was going through this stackoverflow.com/questions/10157616/marklogic-join-query
– Deepan Chelliah
Jan 2 at 11:02
add a comment |
1 Answer
1
active
oldest
votes
One approach is to use a query similar to the following to retrieve the three documents:
cts.search(cts.andQuery([
cts.jsonPropertyValueQuery("id", "100"),
cts.orQuery([
cts.jsonPropertyScopeQuery("name", cts.trueQuery()),
cts.jsonPropertyScopeQuery("domain", cts.trueQuery()),
cts.jsonPropertyScopeQuery("salary", cts.trueQuery())
])
]))
The scope queries test the existence of properties. After retrieving the documents, your SJS code can create a JavaScript or JSON object with the merged properties.
For more efficiency in a production application, you could create indexes on each of the documents using TDE and then join the documents using the Optic API.
However ...
Given that all three documents share the same key, the better approach is almost certainly to persist what you've identified as the output document and filter out any properties you don't need on retrieval.
The DataHub Framework provides a guided way to stage documents and produce harmonized documents.
Hoping that helps,
Thanks! The above code works fine. But, how can I limit it to particular collection or uri???
– Deepan Chelliah
Jan 3 at 11:00
I tried cts.collectionMatch but its returning empty sequence
– Deepan Chelliah
Jan 3 at 11:32
Add a cts.collectionQuery() to the array of subqueries for the cts.andQuery(). The general pattern is that query constructors end in *Query(). cts.collectionMatch() looks up collections in the collection lexicon.
– ehennum
Jan 3 at 17:21
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54003069%2fhow-to-write-java-script-lookup-functions-in-marklogic%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
One approach is to use a query similar to the following to retrieve the three documents:
cts.search(cts.andQuery([
cts.jsonPropertyValueQuery("id", "100"),
cts.orQuery([
cts.jsonPropertyScopeQuery("name", cts.trueQuery()),
cts.jsonPropertyScopeQuery("domain", cts.trueQuery()),
cts.jsonPropertyScopeQuery("salary", cts.trueQuery())
])
]))
The scope queries test the existence of properties. After retrieving the documents, your SJS code can create a JavaScript or JSON object with the merged properties.
For more efficiency in a production application, you could create indexes on each of the documents using TDE and then join the documents using the Optic API.
However ...
Given that all three documents share the same key, the better approach is almost certainly to persist what you've identified as the output document and filter out any properties you don't need on retrieval.
The DataHub Framework provides a guided way to stage documents and produce harmonized documents.
Hoping that helps,
Thanks! The above code works fine. But, how can I limit it to particular collection or uri???
– Deepan Chelliah
Jan 3 at 11:00
I tried cts.collectionMatch but its returning empty sequence
– Deepan Chelliah
Jan 3 at 11:32
Add a cts.collectionQuery() to the array of subqueries for the cts.andQuery(). The general pattern is that query constructors end in *Query(). cts.collectionMatch() looks up collections in the collection lexicon.
– ehennum
Jan 3 at 17:21
add a comment |
One approach is to use a query similar to the following to retrieve the three documents:
cts.search(cts.andQuery([
cts.jsonPropertyValueQuery("id", "100"),
cts.orQuery([
cts.jsonPropertyScopeQuery("name", cts.trueQuery()),
cts.jsonPropertyScopeQuery("domain", cts.trueQuery()),
cts.jsonPropertyScopeQuery("salary", cts.trueQuery())
])
]))
The scope queries test the existence of properties. After retrieving the documents, your SJS code can create a JavaScript or JSON object with the merged properties.
For more efficiency in a production application, you could create indexes on each of the documents using TDE and then join the documents using the Optic API.
However ...
Given that all three documents share the same key, the better approach is almost certainly to persist what you've identified as the output document and filter out any properties you don't need on retrieval.
The DataHub Framework provides a guided way to stage documents and produce harmonized documents.
Hoping that helps,
Thanks! The above code works fine. But, how can I limit it to particular collection or uri???
– Deepan Chelliah
Jan 3 at 11:00
I tried cts.collectionMatch but its returning empty sequence
– Deepan Chelliah
Jan 3 at 11:32
Add a cts.collectionQuery() to the array of subqueries for the cts.andQuery(). The general pattern is that query constructors end in *Query(). cts.collectionMatch() looks up collections in the collection lexicon.
– ehennum
Jan 3 at 17:21
add a comment |
One approach is to use a query similar to the following to retrieve the three documents:
cts.search(cts.andQuery([
cts.jsonPropertyValueQuery("id", "100"),
cts.orQuery([
cts.jsonPropertyScopeQuery("name", cts.trueQuery()),
cts.jsonPropertyScopeQuery("domain", cts.trueQuery()),
cts.jsonPropertyScopeQuery("salary", cts.trueQuery())
])
]))
The scope queries test the existence of properties. After retrieving the documents, your SJS code can create a JavaScript or JSON object with the merged properties.
For more efficiency in a production application, you could create indexes on each of the documents using TDE and then join the documents using the Optic API.
However ...
Given that all three documents share the same key, the better approach is almost certainly to persist what you've identified as the output document and filter out any properties you don't need on retrieval.
The DataHub Framework provides a guided way to stage documents and produce harmonized documents.
Hoping that helps,
One approach is to use a query similar to the following to retrieve the three documents:
cts.search(cts.andQuery([
cts.jsonPropertyValueQuery("id", "100"),
cts.orQuery([
cts.jsonPropertyScopeQuery("name", cts.trueQuery()),
cts.jsonPropertyScopeQuery("domain", cts.trueQuery()),
cts.jsonPropertyScopeQuery("salary", cts.trueQuery())
])
]))
The scope queries test the existence of properties. After retrieving the documents, your SJS code can create a JavaScript or JSON object with the merged properties.
For more efficiency in a production application, you could create indexes on each of the documents using TDE and then join the documents using the Optic API.
However ...
Given that all three documents share the same key, the better approach is almost certainly to persist what you've identified as the output document and filter out any properties you don't need on retrieval.
The DataHub Framework provides a guided way to stage documents and produce harmonized documents.
Hoping that helps,
answered Jan 2 at 18:52
ehennumehennum
5,44697
5,44697
Thanks! The above code works fine. But, how can I limit it to particular collection or uri???
– Deepan Chelliah
Jan 3 at 11:00
I tried cts.collectionMatch but its returning empty sequence
– Deepan Chelliah
Jan 3 at 11:32
Add a cts.collectionQuery() to the array of subqueries for the cts.andQuery(). The general pattern is that query constructors end in *Query(). cts.collectionMatch() looks up collections in the collection lexicon.
– ehennum
Jan 3 at 17:21
add a comment |
Thanks! The above code works fine. But, how can I limit it to particular collection or uri???
– Deepan Chelliah
Jan 3 at 11:00
I tried cts.collectionMatch but its returning empty sequence
– Deepan Chelliah
Jan 3 at 11:32
Add a cts.collectionQuery() to the array of subqueries for the cts.andQuery(). The general pattern is that query constructors end in *Query(). cts.collectionMatch() looks up collections in the collection lexicon.
– ehennum
Jan 3 at 17:21
Thanks! The above code works fine. But, how can I limit it to particular collection or uri???
– Deepan Chelliah
Jan 3 at 11:00
Thanks! The above code works fine. But, how can I limit it to particular collection or uri???
– Deepan Chelliah
Jan 3 at 11:00
I tried cts.collectionMatch but its returning empty sequence
– Deepan Chelliah
Jan 3 at 11:32
I tried cts.collectionMatch but its returning empty sequence
– Deepan Chelliah
Jan 3 at 11:32
Add a cts.collectionQuery() to the array of subqueries for the cts.andQuery(). The general pattern is that query constructors end in *Query(). cts.collectionMatch() looks up collections in the collection lexicon.
– ehennum
Jan 3 at 17:21
Add a cts.collectionQuery() to the array of subqueries for the cts.andQuery(). The general pattern is that query constructors end in *Query(). cts.collectionMatch() looks up collections in the collection lexicon.
– ehennum
Jan 3 at 17:21
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54003069%2fhow-to-write-java-script-lookup-functions-in-marklogic%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
can you post what you have tried so far ?
– Gaurav Rana
Jan 2 at 8:07
I haven't tried anything in javascript, but I was going through this stackoverflow.com/questions/10157616/marklogic-join-query
– Deepan Chelliah
Jan 2 at 11:02