Couchbase
  • Why NoSQL?
  • Couchbase Server
  • Download
  • Resources
  • Careers
Home | Forums | SDKs | SDKs

.NET Query view with 1 key and 1 startkey

2 replies [Last post]
  • Login or register to post comments
Thu, 08/30/2012 - 02:10
WesleyE
Offline
Joined: 05/26/2012
Groups: None

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?

Top
  • Login or register to post comments
Thu, 08/30/2012 - 02:50
WesleyE
Offline
Joined: 05/26/2012
Groups: None

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.

Top
  • Login or register to post comments
Fri, 09/28/2012 - 12:49
john
Offline
Joined: 01/05/2012
Groups: None

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

Top
  • Login or register to post comments
  • Login or register to post comments
  • Login
  • Register

Company

  • About Us
  • Leadership
  • Customers
  • Partners
  • Contact Us

Product

  • Couchbase Server
  • Couchbase SDKs
  • Use Cases
  • Documentation
  • Forums

Open Source

  • Couchbase Project
  • Couchbase vs. CouchDB

Commercial

  • Subscriptions & Support
  • Training & Services

News

  • Blog
  • Newsletter
  • Press Releases
  • Buzz

Follow Us

    
  • Customer Login
  • Terms of Service
  • Privacy Policy
  • Trademark Policy
  • Site Map

© 2013 COUCHBASE All rights reserved.

Sign in to Couchbase Community

close
  • Create new account
  • Request new password
You are logging into the Forums, Wiki and Issue Tracker