I have started working on the MarkLogic database using the Java Client API. I have two use cases for me :-
- 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);
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?