pouchDB distinct where column is-open source projects pouchdb/pouchdb
I need equivalent of select distinct(toc.content)
from table where acModel='7X';
Here is my Document –
{
acModel : "7X",
relYear : 2014,
optId : 11046,
optNum : "2.386.ADW0",
content : "Interior",
cutInFrom : 253,
cutInTo : 9999,
weight : "Standard"
}
Here are the javascript functions –
createIndex: function () {
this.createDesignDoc('by_acModel', function (doc) {
emit(doc.acModel, doc.content);
});
},
getDistinctContent: function(acModel){
var result=[];
function map(opt) {
emit(opt.acModel, {content: content});
}
this.db.query(map,
function (err, response) {
for (var i = 0; i < response.total_rows; ++i) {
if (response.rows[i].key == acModel) {
//Over here I am not sure ... Short of handling it manually, I don't know if I can get pouchDB to give distinct
}
}
});
},
createDesignDoc: function(name, mapFunction) {
var ddoc = {
_id: '_design/' + name,
views: {
}
};
ddoc.views[name] = { map: mapFunction.toString() };
return ddoc;
}
};