couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Luis Miguel Silva <luismiguelferreirasi...@gmail.com>
Subject How to query a view by key?
Date Mon, 04 Apr 2011 16:34:48 GMT
Dear all,

I've been reading the docs but i simply cannot understand how to query
a view by key??

For instance, let's imagine these 2 documents:
{
   "_id": "esxi4-stateless",
   "_rev": "2-fe0aeb05ac93d5f5a08d4befc68f10a6",
   "type": "os",
   "oslist": [
       "SOE-RHEL-5_5-2H10_0-Statelite-pm",
       "esxi4-stateless",
       "rhel53-statelite-pm",
       "rhel54-statelite-pm"
   ],
   "vmoslist": [
       "rhel48-stateful",
       "rhel53-stateful",
       "rhel53-stateful-cluster",
       "rhel54-stateful",
       "SOE-RHEL-5_5-2H10_0-Stateful",
       "rhel54-stateful-cluster",
       "rhel53-statelite-vm",
       "rhel54-statelite-vm",
       "SOE-RHEL-5_5-2H10_0-Statelite-vm",
       "win2k3-stateful-32-std",
       "win2k3-stateful-32-ent",
       "win2k3-stateful-32-ent-cluster",
       "win2k3-stateful-64-std",
       "win2k3-stateful-64-ent",
       "win2k3-stateful-64-ent-cluster",
       "win2k8-stateful-64-std",
       "win2k8-stateful-64-ent",
       "win2k8-stateful-64-ent-cluster",
       "win2k8R2-stateful-64-std",
       "win2k8R2-stateful-64-ent",
       "win2k8R2-stateful-64-ent-cluster",
       "P2V-WIN,P2V-RHEL"
   ]
}

and
{
   "_id": "rhel54-stateful",
   "_rev": "1-170a66778927ee575ab080a33985d44e",
   "type": "os",
   "oslist": [
       "SOE-RHEL-5_5-2H10_0-Statelite-pm",
       "esxi4-stateless",
       "rhel53-statelite-pm",
       "rhel54-statelite-pm"
   ]
}

So i created this view to query them:
function(doc) {
	if (doc.type == "os")
	{
		emit(doc._id,
			{
				os: doc._id,
				OSLIST: doc.oslist,
				VMOSLIST: doc.vmoslist,
			}
		);
	}
}

And consuming it directly
(http://xkitten.ac:5984/momdb/_design/os/_view/getOS) produces:
{"total_rows":2,"offset":0,"rows":[
{"id":"esxi4-stateless","key":"esxi4-stateless","value":{"os":"esxi4-stateless","OSLIST":["SOE-RHEL-5_5-2H10_0-Statelite-pm","esxi4-stateless","rhel53-statelite-pm","rhel54-statelite-pm"],"VMOSLIST":["rhel48-stateful","rhel53-stateful","rhel53-stateful-cluster","rhel54-stateful","SOE-RHEL-5_5-2H10_0-Stateful","rhel54-stateful-cluster","rhel53-statelite-vm","rhel54-statelite-vm","SOE-RHEL-5_5-2H10_0-Statelite-vm","win2k3-stateful-32-std","win2k3-stateful-32-ent","win2k3-stateful-32-ent-cluster","win2k3-stateful-64-std","win2k3-stateful-64-ent","win2k3-stateful-64-ent-cluster","win2k8-stateful-64-std","win2k8-stateful-64-ent","win2k8-stateful-64-ent-cluster","win2k8R2-stateful-64-std","win2k8R2-stateful-64-ent","win2k8R2-stateful-64-ent-cluster","P2V-WIN,P2V-RHEL"]}},
{"id":"rhel54-stateful","key":"rhel54-stateful","value":{"os":"rhel54-stateful","OSLIST":["SOE-RHEL-5_5-2H10_0-Statelite-pm","esxi4-stateless","rhel53-statelite-pm","rhel54-statelite-pm"]}}
]}

But what about if i just want to get the register for _id = "esxi4-stateless" ??

I've been trying with:
http://xkitten.ac:5984/momdb/_design/os/_view/getOS?key="esxi4-stateless"&include_docs=true
http://xkitten.ac:5984/momdb/_design/os/_view/getOS?key=["esxi4-stateless",1,{}]&include_docs=true
and a mixture of different things but i JUST can't seem to get it?!

Could someone please explain how to correctly query the REST web
service to get what i want??

Thanks in advance,
Luis

Mime
View raw message