简体   繁体   中英

Need help in converting the code from couchdb to couchbase

I have same view in couchbase and couchdb. The name of the view is "TotalPosts" I am pasting my view code below:

This is map:

 function(doc) {
    emit("Total", 1);
        emit("TotalParticipants", doc.participants.length);
        if(doc.status == "1"){
            emit("Open", 1);
        } else if(doc.status == "2") {
            emit("Wah", parseInt(doc.wah_points));
        }
    }

This is the reduce code:

function (key, values, rereduce) {
    return sum(values);
}

The result of the view will be like this:

Key                    value

Open                     7
Total                    8
TotalParticipants        20
Wah                      50

Now i am able to execute and retrieve the view result in couchdb using this code:

public IEnumerable<Newtonsoft.Json.Linq.JToken> GetAllStatistics()
         {
             oCouchDB.SetDefaultDesignDoc("Statistics");

             ViewOptions voStats = new ViewOptions();
             voStats.GroupLevel = 1;
             voStats.Stale = true;

             var results = oCouchDB.View("TotalPosts", voStats);

             return results.Rows;

        }

Now this is my code for couchbase:

public IEnumerable<Newtonsoft.Json.Linq.JToken> GetAllStatistics()
         {
             var results = oCouchbase.GetView("Statistics", "TotalPosts");
             return-----// what is the equivalent code here

        }

Kindly help me out....

Couchbase returns a JSON object just like CouchDB does. Should work with the same code, or inspect the 'results' variable to see what's inside.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM