incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Luis Miguel Silva <>
Subject Views question? (entity relationship)
Date Sun, 03 Apr 2011 22:55:46 GMT
Dear all,

I'm having some trouble defining a view with entity relationships.

Here is an example on what i need to do:
   "_id": "node01",
   "_rev": "2-eec9e84f8146d05f8116a5e064cf87e9",
   "type": "node",
   "amemory": 14543,
   "cmemory": 49118,
   "cproc": 16,
   "cpuload": 2.379,
   "netaddress": "",
   "power": "on",
   "primary_state": "UP",
   "secondary_state": "Unknown:sshd",
   "os": "esxi4-stateless",
   "alias": "node01",
   "vlans": "[vlan611]",
   "variables": [
           "provision_status": 2
           "another_variable": "something"
   "aproc": 16,
   "vmcount": 6,
   "cpupercent": 14.8677794448612,
   "acores": 8,
   "ccores": 8,
   "threads": 16,
   "cpuclock": 2666,
   "numvms": 13,
   "hvtype": "esx",
   "htenabled": true

And then...
   "_id": "esxi4-stateless",
   "_rev": "2-fe0aeb05ac93d5f5a08d4befc68f10a6",
   "type": "os",
   "oslist": [
   "vmoslist": [

And my view looks like:
function(doc) {
	if (doc.type == "node")
				node: doc._id,
				STATE: doc.secondary_state,
				OS: doc.oslist,
				ALIAS: doc.alias,
				FEATURE: doc.vlans,
				"GMETRIC[numvms]": doc.numvms,
				NETADDR: doc.netaddress,
				VARATTR: { "HVTYPE":doc.hvtype},
				VARIABLE: doc.variables,

So my question is, how do i get the oslist and vmoslist from the
document whose _id = my register's doc.os key ?

I basically need to understand how i can query the entire database,
getting all the nodes and, while i'm querying all the nodes, get the
appropriate oslist and vmoslist (so i do not have to store these
fields more than once since they only vary based on "os" key).

I've been reading the EntityRelationship wiki page
( but i really do
not understand how can i map without specifying a key.
In the "phone directory example", i would have to specify the
individual key i want to get in order to map relations between
documents and that's not what i want to do.

Any thoughts?

Thank you,

View raw message