I wrote some document to a bucket
1NR1 {id:1NR1, Type:1NR, p1:0,p2:0,p3:0,p4:0}
1NR2 {id:1NR2, Type:1NR, p1:0,p2:0,p3:0,p4:0}
1NR3 {id:1NR3, Type:1NR, p1:0,p2:0,p3:0,p4:0}
…
1NR100 {id:1NR3, Type:9NR, p1:0,p2:0,p3:0,p4:0}
…
I hope to query all documents which ‘Type’ are 1NR
so I created a view(name is ‘1nr’)
view code
function (doc, meta) {
if (doc.Type && doc.Type == “1NR” && doc.id) {
emit(doc.id, null);
}
}
then I executed
var couchbase = require(‘couchbase’);
var db = new couchbase.Connection({host: ‘localhost:8091’, bucket: ‘default’});
…
var query = db.view(‘1nr’, ‘by_Type’);
query.query(function(err, results) {
for(i in results)
console.log(results[i]); // let’s iterate all documents
});
but it always return null
another question is ‘by_Type’ in
var query = db.view(‘1nr’, ‘by_Type’);
If I hope to query Type, just need to set the by_Type
query id, just need to set the by_id
Is it right?
Your comment welcome