{"id":8090,"date":"2015-11-26T13:35:58","date_gmt":"2015-11-26T13:35:58","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2015\/11\/26\/pouchdb-distinct-where-column-is-open-source-projects-pouchdb-pouchdb\/"},"modified":"2022-08-30T15:03:01","modified_gmt":"2022-08-30T15:03:01","slug":"pouchdb-distinct-where-column-is-open-source-projects-pouchdb-pouchdb","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2015\/11\/26\/pouchdb-distinct-where-column-is-open-source-projects-pouchdb-pouchdb\/","title":{"rendered":"pouchDB distinct where column is-open source projects pouchdb\/pouchdb"},"content":{"rendered":"<p>I need equivalent of <code>select distinct(toc.content)<\/code> from table where <code>acModel='7X';<\/code><\/p>\n<p>Here is my Document &#8211;<\/p>\n<pre><code>{\n    acModel : \"7X\",\n    relYear : 2014,\n    optId : 11046,\n    optNum : \"2.386.ADW0\",\n    content : \"Interior\",\n    cutInFrom : 253,\n    cutInTo : 9999,\n    weight : \"Standard\"\n}\n<\/code><\/pre>\n<p>Here are the javascript functions &#8211;<\/p>\n<pre><code>createIndex: function () {\n    this.createDesignDoc('by_acModel', function (doc) {\n        emit(doc.acModel, doc.content);\n    });\n},\ngetDistinctContent: function(acModel){\n    var result=[];\n    function map(opt) {\n        emit(opt.acModel, {content: content});\n    }\n    this.db.query(map,\n        function (err, response) {\n            for (var i = 0; i &lt; response.total_rows; ++i) {\n                if (response.rows[i].key == acModel) {\n                     \/\/Over here I am not sure ... Short of handling it manually, I don't know if I can get pouchDB to give distinct\n                }\n            }\n    });\n},\ncreateDesignDoc: function(name, mapFunction) {\n    var ddoc = {\n        _id: '_design\/' + name,\n        views: {\n        }\n    };\n    ddoc.views[name] = { map: mapFunction.toString() };\n    return ddoc;\n}\n};\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I need equivalent of select distinct(toc.content) from table where acModel=&#8217;7X&#8217;; Here is my Document &#8211; { acModel : &#8220;7X&#8221;, relYear : 2014, optId : 11046, optNum : &#8220;2.386.ADW0&#8221;, content : &#8220;Interior&#8221;, cutInFrom : 253, cutInTo : 9999, weight : &#8220;Standard&#8221; } Here are the javascript functions &#8211; createIndex: function () { this.createDesignDoc(&#8216;by_acModel&#8217;, function (doc) { [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-8090","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/8090","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=8090"}],"version-history":[{"count":1,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/8090\/revisions"}],"predecessor-version":[{"id":8633,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/8090\/revisions\/8633"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=8090"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=8090"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=8090"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}