Sam,

Thanks for the reply!  Here are my specific questions/concerns:

1- is >>
*cts.andQuery([cts.collectionQuery("latest"),cts.collectionQuery("zzz")<< *the
best way to query for the latest ("latest") documents in a bitemporal
collection ("zzz") ?  I assume that a query of only "latest" or only "zzz"
will be overly broad?  It seems like there might be a more succinct syntax
given that query of the latest in such a collection would be the most
common (or at least a very common) case?

2- is a filter on some other property >>
*cts.jsonPropertyValueQuery("papa","Dan")]);<<* to be collected with
andQuery() as I have it, assuming that my approach to the above (#1) is
already best practice?

3- when wanting to transform the result (in this case, strip off some child
leafs of the document tree structure and then duplicate data from a parent
leaf to "flatten" results from a middle-tier leaf), is the server-side
JavaScript I proposed the most reasonable method?  Does it constitute best
practice?  Again, this type of query result transformation is common enough
that MongoDB has aggregation operators to do it more succinctly ($project
and $unwind).  I just want to be sure that my method is the best approach
for MarkLogic.

-John

On Wed, Apr 12, 2017 at 9:38 AM, Sam Mefford <[email protected]>
wrote:

> Can you give some context as to what "a better way" should do better than
> your solution?
>
> Sam Mefford
> Senior Engineer
> MarkLogic Corporation
> [email protected]
> Cell: +1 801 706 9731 <(801)%20706-9731>
> www.marklogic.com
>
> This e-mail and any accompanying attachments are confidential. The
> information is intended solely for the use of the individual to whom it is
> addressed. Any review, disclosure, copying, distribution, or use of this
> e-mail communication by others is strictly prohibited. If you are not the
> intended recipient, please notify us immediately by returning this message
> to the sender and delete all copies. Thank you for your cooperation.
> ------------------------------
> *From:* [email protected] [
> [email protected]] on behalf of John Muehlhausen [
> [email protected]]
> *Sent:* Tuesday, April 11, 2017 4:08 PM
> *To:* [email protected]
> *Subject:* [MarkLogic Dev General] Trying to find equivalent to MongoDB
> aggregate( match -> project[include] -> project[exclude] -> unwind )
>
> I have a MarkLogic solution in server-side JavaScript but I'm thinking
> there must be a better way?  The document is in a bitemporal store called
> "zzz".
>
> I want to do the following:
>
> Search documents in both the "zzz" and "latest" collections (i.e. the most
> recent version of "zzz").  Find the documents where papa="Dan".  Of these
> results, eliminate the "child" arrays from "children" items.  Return
> {yoyo,hoop} documents where there will be as many return documents as there
> are children.  In other words, there is denormalization where yoyo is
> duplicated.  A source document with two children would produce two output
> documents.  JavaScript follows example document:
>
> {
> "systemStart": "2017-04-11T17:46:48.468112Z",
> "systemEnd": "9999-12-31T11:59:59Z",
> "validStart": "2014-04-03T11:00:00",
> "validEnd": "2014-04-03T16:00:00",
> "id": "2017-04-11/34567",
> "date": "2017-04-11",
> "yoyo": "12345",
> "papa": "Dan",
> "children":
> [
> {
> "hoop": "A",
> "child":
> [
> {
> "a": "a"
> }
> ]
> }
> ,
> {
> "hoop": "B",
> "child":
> [
> {
> "a": "b"
> }
> ]
> }
> ]
> }
>
> My current solution:
>
> var query=cts.andQuery([cts.collectionQuery("latest"),cts.
> collectionQuery("zzz"),cts.jsonPropertyValueQuery("papa","Dan")]); var
> results=cts.search(query); var arr = Array(); for(var result of results) {
> result = result.toObject(); var len = result.children.length; for(var
> i=0;i<len;i++) { delete result.children[i].child; result.children[i].yoyo =
> result.yoyo; arr.push(result.children[i]); } } arr;
>
> Current output in Query Console, assuming two documents are found:
>
> [
> {
> "hoop": "A",
> "yoyo": "12345"
> }
> ,
> {
> "hoop": "B",
> "yoyo": "12345"
> }
> ,
> {
> "hoop": "A",
> "yoyo": "12345"
> }
> ,
> {
> "hoop": "B",
> "yoyo": "12345"
> }
> ]
>
> In MongoDB the query looks something like this (without the bitemporal of
> course):
>
> db.zzz.aggregate( [ {$match: {“papa” : “Dan”}}, {$project: {_id: false,
> “yoyo”: true, “children”: true} }, {$project: {“children.child”:false}},
> {$unwind: “$children”} ] )
>
> Thanks,
> John
>
> _______________________________________________
> General mailing list
> [email protected]
> Manage your subscription at:
> http://developer.marklogic.com/mailman/listinfo/general
>
>
_______________________________________________
General mailing list
[email protected]
Manage your subscription at: 
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to