You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Luscus Readbeard <lu...@googlemail.com> on 2012/02/02 00:37:11 UTC

Re: Using JavaScript libs in a view's map function

Thanks for your answers,

@Paul: right, for CommonJS I was talking bullshit... Thanks to point it out.

@Jens: this is what I am trying to do:

I have one app managing an hierarchy of documents of different types -
every parent can have 0 or n childs.
In the end the app mainly uses the document type that is lowest in the
hierarchy and this one holds the parent chain in some array of doc ids
(lets call this type "baseDoc").

An other app is used to gather information about some  baseDoc, it
does not update or read this baseDoc, it only stores data about this
doc referencing it with its id.

The problem is that the information I want to gather are not the same
for every baseDoc, in fact those information depends on the whole
parent chain of the baseDoc.

My first idea was to create a data structure with 3 different types of
documents:
 - parameters (which holds some datatype, creation date and other stuff)
 - groups (on with we can attach several parameters and a list of members)
 - categories (to be able to filter the group-parameter relations)
 - one view ("group-membership-view") showing all members with a key
[member.id,category.name] and the value holding the parameter array.
And a reduce function aggregating the parameter array if the member is
in more than one group of the same category...

Now I am able to assign any element of the baseDoc hierarchy to some
group with some parameters attached to it.
But I failed to find a way to get the complete parameter information
about one baseDoc and its hierarchy...

I wanted to use views because it hat the great appeal to keep the
aggregation of parameter up to date after some hierarchy change -->
changing the hierarchy of one baseDoc changes its parents array,
triggers a doc change event and the reprocessing of the view result
for it...

Therefore I was asking if there is a way of reading views or docs in a
map function. I would have implemented the map to go through the
baseDocs, checking every parent if it could be found in the
"group-membership-view" and aggregating the related parameters to one
single array... (Hierarchy changes are rare, the processing time is
not relevant)

One parameter list for one baseDoc.id, depending on the hierarchy and
with auto-update in a case of hierarchy change. That was sounding
promising...

But I may be completely misleaded, as I say I am new to Doc Databases
and to CouchDB, maybe there is an other way to "think"/resolve this
problem.

The point is, I need 2 apps which does not mix up data by changing
each others documents, but only reference them in one direction:
secondary data (baseDoc related information) build on separated
primary data (baseDoc and its hierarchy).


I hope I was clear - it was a long day and it is late    ;)

Thanks for your time