2

In my program I need to join 2 and more collections by some json properties.

When I run only subsequence method it return array of json objects but when I use it in op.fromLiterals in my optic plan it returns a list of document uris.

I can't use the method op.fromSearch because I can't upgrade to a later MarkLogic version.

I need something like this to work:

var items = fn.subsequence(search).toArray();
op.fromLiterals(items)
.joinInner(article, op.on('fragmentId', 'viewDocId'))
.result()

But now items is a list of document locations (document_1.json) and this code gives me an error:

XDMP-ARGTYPE: xdmp.documentGet(cts.doc("/Documents/document_1.json"))

Solution: I push properties to results in this way: results.push({id: doc.toObject()["document_id"]}); and its work fine.

  • what is it that you need included? You could try producing an array of objects with the information that you need for your literals. `const results = []; for (const doc of fn.subsequence(search, 1, 5)){ results.push( {"uri": xdmp.nodeUri(doc), "nodeCount": doc.xpath("count(//node())") } ) } const test = op.fromLiterals(results)` – Mads Hansen Jan 13 '22 at 18:39
  • I need to join two collections of documents and select some columns to display. – Michal Sobanski Jan 14 '22 at 16:59
  • Yeah, so it seems that when you get the search results as an array with `.toArray()` it creates an array of quoted strings (like `xdmp:quote(doc)`) and you lose some of that info you would would want for your literals. But, you can produce your own array (minimal example above) with whatever doc properties or info you need, and use that in your `op.fromLiterals()`. I can flesh out an example if you can describe some of what you would want from the search results. – Mads Hansen Jan 14 '22 at 18:49
  • I edited post with error message – Michal Sobanski Jan 17 '22 at 09:16
  • `xdmp.documentGet()` expects a location of a doc to fetch from HTTP or the filesystem. You are using `cts.doc()` which returns a document, not a location. But I don't see where/how that is applied in the code snippet. – Mads Hansen Jan 17 '22 at 13:25
  • This is my whole code fn.subsequence(search).toArray() returns me a list of cts.doc() with document address. When I pick one property from doc object ({id: doc.toObject()["document_id"]} it work fine, but I need whole object in literal. If You have any idea how to fix my problem I will be greatfull :) – Michal Sobanski Jan 19 '22 at 19:08
  • `{id: doc.toObject()["document_id"], doc: xdmp.quote(doc)}` ? – Mads Hansen Jan 19 '22 at 19:27
  • quote is nice but I have to access some other property, because I will need to do some joins on that's properties. I tried something like this: results.push({ id: document["document_id"], document_relations: document["relations"] }); but after adding document_relations property, script return me an error: XDMP-BADRDFVAL: plan.literalTable(Sequence({id:1639, relations: ... – Michal Sobanski Jan 19 '22 at 20:17

0 Answers0