Skip to content
No description or website provided.
Find file
New pull request
Pull request Compare This branch is 4 commits ahead, 5 commits behind couchbaselabs:master.
Fetching latest commit...
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Sample project demonstrating how to generate basic Couchbase Views with the CouchbaseClient and custom attributes on data objects

Usage (Models)

Reference Couchbase.ModelViews.Framework in your models project. Decorate the class with the name of the design doc.
Decorate properties with the name of the views to which they should be keys. Optionally, include the order in which the properties should be emitted.

public class Beer
    public string Id { get; set; }

    [CouchbaseViewKey("by_abv_and_name", "name", 1)]
    [CouchbaseViewKey("by_name", "name")]
    public string Name { get; set; }

    public string Description { get; set; }

    [CouchbaseViewKey("by_abv_and_name", "abv", 0)]
    public float ABV { get; set; }

    [CouchbaseViewKey("by_brewery", "breweryId")]
    public string Brewery { get; set; }

public class Brewery
    [CouchbaseCollatedViewKey("all_with_beers", "beer", "name", "brewery_id")]
    public string Id { get; set; }

    [CouchbaseViewKey("by_name", "name")]
    public string Name { get; set; }

    public string Description { get; set; }

    [CouchbaseViewKeyCount("by_state", "state", 1)]
    public string State { get; set; }

    [CouchbaseSpatialView("by_location", "geo.lng", 0)]
    public float Longitude { get; set; }

    [CouchbaseSpatialView("by_location", "", 1)]
    public float Latitude { get; set; }         

Usage (Console App)

In app.config, list the assemblies from which to build views (along with the CouchbaseCluster configuration).

<?xml version="1.0" encoding="utf-8" ?>
    <sectionGroup name="modelViews">
      <section name="assemblies" type="System.Configuration.DictionarySectionHandler"/>      
    <section name="couchbase" type="Couchbase.Configuration.CouchbaseClientSection, Couchbase"/>

      <add key="DemoModels" value="CouchbaseModelViews.DemoModels" />

    <servers bucket="beer-sample" bucketPassword="">
      <add uri="http://localhost:8091/pools"/>      

Run the console application. The sample Beer class above will produce the following views:

  "views": {
    "all": {
      "map": "function(doc, meta) { \r\n\t if (doc.type == \"beer\") { \r\n\t\t emit(null, null); \r\n\t } \r\n }"        
    "by_name_and_abv": {
      "map": "function(doc, meta) { \r\n\t if (doc.type == \"beer\" && && doc.abv) { \r\n\t\t emit([, doc.abv], null); \r\n\t } \r\n }"
    "by_name": {
      "map": "function(doc, meta) { \r\n\t if (doc.type == \"beer\" && { \r\n\t\t emit(, null); \r\n\t } \r\n }"
    "by_brewery": {
      "map": "function(doc, meta) { \r\n\t if (doc.type == \"beer\" && doc.breweryId) { \r\n\t\t emit(doc.breweryId, null); \r\n\t } \r\n }"
Something went wrong with that request. Please try again.