1

I have started working on the MarkLogic database using the Java Client API. I have two use cases for me :-

  1. Extract all the documents which are in the same collection and which are in the form of JSON where a particular date is less than or equal to a certain date.

JSON is in the form

{
    "id"  : "12345"
    "date" : "2012-12-12",
    "messageType" : "dummy_type",
    ....
}

I am able to do this using the below code :-

val queryMgr = client.newQueryManager();
var rawHandle: StringHandle = new StringHandle
rawHandle.withFormat(Format.JSON).set("{\"$query\": {\"tradingDate\": { \"$le\":\""+ date + "\"}, \"$filtered\": true}}");
var querydef: RawQueryByExampleDefinition = queryMgr.newRawQueryByExampleDefinition(rawHandle);  
querydef.setCollections(collectionName);
jsonDocMgr.search(querydef, 1); 
  1. Now I have multiple documents in the database, where multiple documents are part of one id but there message types are different. As in I have A, B and C as message types with all have id as 12345. Now depending upon the date parameter in type C, I want to make a decision whether all documents (A, B, and C) need to be fetched or should not be fetched.

    Could anyone please suggest whether I can create javascript functions and pass it to the MarkLogic db using the Java Client API or any other thing or any references?

1 Answer 1

1

I'd recommend you start by looking at transforming search results. To use them you'll need to follow the instructions to install and test the transform via REST or Java, then add querydef.setResponseTransform(new ServerTransform("yourTransformName") then call QueryManager.search(querydef, new SearchHandle()). You can decide what your transform should return for each query match.

Sign up to request clarification or add additional context in comments.

2 Comments

Hi Sam, the transformation will help transform individual record from the Marklogic database as the content parameter in the transformation function is equivalent to single record or document. But here one document is dependent on another document. How do I take care of this scenario?
Is there anything provided in Java client app where in I create a Java script file containing functions to manipulate all the documents and then pass on the java script file to Marklogic and then the database will render the result depending on the logic written in Javascript file??

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.