I am using PouchDB v3.6.0
I have a query like below:
var ddoc = {
_id: '_design/my_indexNew',
views: {
by_name1: {
map: function (doc) { emit(doc.Name); }.toString()
}
}
};
// save it
db.put(ddoc).then(function () {
alert('Idx created');
// success!
}).catch(function (err) {
if (err.status != 409) { // some error other than 409 (already exists)
alert(err);
}
});
// Now use the Query
var myId = 'AADHIYA';
db.query('by_name1', {
key : myId,
include_docs : true
}).then(function (result) {
// handle result
alert('found');
}).catch(function (err) {
// handle errors
alert('not found');
});
However, the above query is using the URL as below:
As can be seen in the Chrome debugger console, this causes a '404' error, as index name is same as view name.
However, if I manually correct the URL as below (which has correct index name) http://127.0.0.1:5984/ssarathi/_design/my_indexNew/_view/by_name1?include_docs=true&key=%22AADHIYA%22&_nonce=1434631865806
I can see the intended result.
Why db.query causes index name to have same as that of view name?
Thanks,
Sathya
db.query('foo')
is shorthand fordb.query('foo/foo')
, where the part on the left is the design doc ID and the part on the right is the view name.So since your design doc is
_design/my_indexNew
and your view isby_name1
, you need to do this instead: