Thanks, Jason!

In my case, even being able to emit multiple rows within a document
won't work since I'm having to build the API to suit an existing
document structure.

I spent some time researching alternatives and found a NPM library that
seems to do exactly what I want:

https://github.com/sunnewehr/map-json

The README for this repo may be a better articulation of my needs, but I
figured I'd share since this may be of use to others who are trying to
store more granular documents and compose them into a larger one as part
of building APIs.

On Sat, Dec 17, 2016, at 04:12 AM, Jason Smith wrote:
> Hi, David. Great question! I think it is producing three separate *rows*
> but not necessarily documents.
> 
> In other words, if you query the view ?include_docs=true then you will
> have
> three rows, with "doc" being one document out of the larger set.
> 
> Is it possible to change your application code to be aware of this new
> fact. In other words, is it possible to change your application code to
> understand that the view now has *clumps* of rows, all of which refer to
> the same master document, instead of the current way where the view has
> *individual* rows, each of which is considered independent?
> 
> If the answer is no, then I am afraid CouchDB cannot do what you need, at
> least not in a single query. (In my opinion, accomplishing everything in
> one big request is overrated. If you allow for multiple return-trips, a
> whole world of possibilities opens up.) But anyway, you might imagine,
> what
> should CouchDB do if instead of 3 child documents, there are 3,000, or 3
> million? That is a very "fat" row, and it almost literally cuts against
> the
> grain. CouchDB prefers tall lists, not fat lists. If you call emit() 3
> million times, then CouchDB will have no problems whatsoever.
> 
> On Sat, Dec 17, 2016 at 8:09 AM, David Squier <[email protected]>
> wrote:
> 
> > Thanks, Jan. I tried that, but it produced three separate documents. I
> > was hoping to get everything in a single document.
> >
> > On Fri, Dec 16, 2016, at 02:10 AM, Jan Lehnardt wrote:
> > >
> > > > On 15 Dec 2016, at 20:56, David Squier <[email protected]> wrote:
> > > >
> > > > Greetings,
> > > >
> > > >
> > > >
> > > > I have a master document that contains multiple references to child
> > > > documents. I want to use the Linked Documents feature to "compose" a
> > > > master document that replaces all the child document references (i.e.,
> > > > keys) with the actual document contents.
> > > >
> > > >
> > > > I can do this with a single linked document using the following emit
> > > > in a view:
> > > >
> > > >
> > > > emit(doc._id, { _id: "child_document_1" });
> > >
> > > Assuming:
> > >
> > > {
> > >   _id: “main_doc”,
> > >   "child_documents”: [
> > >     "child_doc_id_1”,
> > >     "child_doc_id_2”,
> > >     "child_doc_id_3”
> > >   ]
> > >
> > > }
> > >
> > > then
> > >
> > > function(doc) {
> > >   doc.child_documents.forEach(function(child_doc) {
> > >     emit(doc._id, { _id: child_doc._id})
> > >   })
> > > }
> > >
> > > will do the trick.
> > >
> > > Best
> > > Jan
> > > --
> > >
> > >
> > > >
> > > >
> > > >
> > > > With the include_docs=true, this populates the document contents for
> > > > child_document_1 as expected. However, I have not found a way do this
> > > > for multiple documents.
> > > >
> > > >
> > > > For example, I'd like to do something like the following:
> > > >
> > > >
> > > >
> > > > emit(doc._id, "children": { _id: "child_document_1", _id:
> > > > "child_document_2" });
> > > >
> > > >
> > > > And have both child documents replaced with their document bodies._id.
> > > > However, it appears the Linked Documents syntax is specific in wanting
> > a
> > > > single document referenced and therefore only allowing that documents
> > > > contents to be populated.
> > > >
> > > >
> > > > Is this even possible? If not through Views, through some other
> > > > mechanism?
> > > >
> > > >
> > > > NOTE: I do not want to generate multiple documents (i.e., use multiple
> > emit() statements) as my goal is to return a single document.
> > > >
> > > >
> > > > Thanks much!
> > > >
> > > >
> > >
> > > --
> > > Professional Support for Apache CouchDB:
> > > https://neighbourhood.ie/couchdb-support/
> > >
> >

Reply via email to