.NET Query view with 1 key and 1 startkey
Hi,
I would like to query a key with two keys, currently this is my view code:
function (doc, meta) {
if(doc.timestamp)
{
var splittedId = doc._id.split("::"); //Get count from _id
emit([doc.sensorId, splittedId[3]], doc);
}
}The _id looks like this: DATA::9bf31c7ff062936a::c51ce410c124a10e::2636. The split returns the 2636 part.
I would like to query on a doc.sensorId and where the id number is between a certain range. Can I build a query in .NET to get this kind of behaviour?
Hi Wesley,
Sorry to be slow to reply!
A couple of notes. You can query on array keys by passing the view an array of keys...
var view = client.GetView("design", "view").Key(new object[] { "key1", "key2" });
The same is true of StartKey and EndKey.
Second, you probably don't want to emit the doc as the value, since that will create an index containing the full doc. It's better to look up the doc by id.
For more, see my recent blog post on view querying in .NET.
http://blog.couchbase.com/strongly-typed-views-net-client-library
-- John
I've fixed it using the Skip and Limit functions to effectively create a range of keys. I would still like to know if it is possible to set the startkeys and keys command to only 1 or some of the keys that are being emitted.