How to get total rows count of a subset of a view

We are trying to get total rows count of a view filtering with particular key. We admit one problem

  1. No matter whatever key we set the total_rows value remain same

anyone have some explanation? and how to get total rows count of a view filtering with particular key.

Please help…

1 Like

Hi, could you please show us how you do this? Are you using the built in count reduce?

total_rows shows how many rows were indexed by the view. If you want to determine how many rows match your query, you would use a reduce function using the built-in _count reducer. If you want to get the actual rows (rather than just their count), just set reduce=false in your query.

1 Like

Do we have any possibility to create reduce function using rest. Am using cordova-couchbase-lite. plugin.

My map function as follows.

                    couchlite.messages = new $couchbase(url, "test");
                    // 2
                    $scope.message = JSON.stringify("Database Creation");
                    couchlite.messages.createDatabase().then(function (result) {
                    $scope.message = JSON.stringify("Database created");
                        var messageViews = {
                            messages: {
                                map: function (doc) {
                                    if (doc.type) {
                                        emit(doc.updatedOn, 
                                            { 
                                                 type:doc.type,
                                                 title: doc.title,
                                                 description: doc.description,
                                                 featuredImage:doc.featuredImage,
                                                 rev: doc._rev,
                                                 totalLike:doc.totalLikes,
                                                 totalShares:doc.totalShares,
                                                 authorName:doc.author.firstname+" "+doc.author.lastName,
                                                 updatedOn:doc.updatedOn
                                            }
                                        )
                                    }
                                }.toString()
                            }
                        };
                        couchlite.messages.createDesignDocument("_design/message", messageViews);
                        couchlite.messages.listen();