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

Parameter Passing from VS2010 to CouchBase DB through GetView()

2 replies [Last post]
  • Login or register to post comments
Fri, 12/14/2012 - 06:27
bhansalisuraj
Offline
Joined: 12/14/2012
Groups: None

Hello All,

I have bunch of records(Documents)into bucket.
I have created view for this same. Now I want to retrieve single record from this bunch by passing parameter from our Front end side(C#). I have tried extension method of GetView like Contains and Where. But I didn't get anything from them.

Can you please provide any solution for this same? Also I requested to please tell can we have any return type of Emit which is in CouchBase View.

Please check this code as below.

var result = c.GetView("Design Name", "View Name").Where();

var result = c.GetView("Design Name", "View Name").Contains();

Please check code as below for Emit

function (doc, meta) {

if (meta.id.indexOf("Emp.") == 0)
{
emit([doc.empId, doc.empName, doc.salary], null);

}

Quick response will be appreciable.

Thanks in advance.....

Suraj B

Top
  • Login or register to post comments
Fri, 12/14/2012 - 09:32
tgrall
Offline
Joined: 09/05/2012
Groups: None

Hello,

I am not a C# expert so I will give you a generic answer on Views, but it should help you to see how to use them in your application.

So based on your code the View will generate the index that will look like:

key : [1, "john", 3000]
value: null

not sure how you want to use this, because with View you can only query (get, range), and sort/group on the key itself.

So if you requirement is to lookup your user by ID or Name or Salary depending of business logic you have to create 3 views (or I will say 2 because the employee id is probably the document id)

So once you have create a view that emits the "Employee Name" and another one that emits the "Salary" you should be able to query then using for example:
- c.GetView("Design Name", "View Name").key("John"); will return the document employees name John
- c.GetView("Design Name", "View Name").StartKet(1000).EndKEy(5000); will return the employee with salary between 1000 and 5000

Regards
Tug

Regards
Tug

__________________

Tug
@tgrall

Top
  • Login or register to post comments
Sun, 12/16/2012 - 21:47
bhansalisuraj
Offline
Joined: 12/14/2012
Groups: None

Hello Tug,

Thank you for your quick response.

You are right, With view we can only query (get, range), and sort/group on the key itself.
I have tried these both methods. I want to try GetView().Contains() and GetView().Where() these two methods.

Can we have any idea about these two methods? I want to pass Key as parameter to these methods.

Thanks in advance.

Thanks & Regards,
Suraj B

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