Parameter Passing from VS2010 to CouchBase DB through GetView()
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
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
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