Javascript 索引袋数据库多维文档
正在寻找索引数据库的方法 当我有多个维度时,找不到索引的方法 这是我的文档客户端示例 请注意,客户可能有一些发票Javascript 索引袋数据库多维文档,javascript,pouchdb,Javascript,Pouchdb,正在寻找索引数据库的方法 当我有多个维度时,找不到索引的方法 这是我的文档客户端示例 请注意,客户可能有一些发票 { clientId : 2 clientName : 'toto' phoneNumber : '2342342' invoices : [ { invoiceNumber : '12312313' , Amount : 234242, barCode : '
{
clientId : 2
clientName : 'toto'
phoneNumber : '2342342'
invoices : [
{
invoiceNumber : '12312313' ,
Amount : 234242,
barCode : '1234324',
},
{
invoiceNumber : '12312313' ,
Amount : 234242,
barCode : '1234324',
}
]
}
{
clientId : 3
clientName : 'tata'
phoneNumber : '2342342'
invoices : [
{
invoiceNumber : '3542435' ,
Amount : 234242,
barCode : '1234324',
},
{
invoiceNumber : '235423' ,
Amount : 234242,
barCode : '23454235',
}
]
}
我想能够找到客户的发票号码和条形码号码
所以索引这些是很重要的
谢谢你的帮助
我看过
及
到目前为止,运气不太好如上所述:
。。。可以在map函数中多次调用emit()
函数,,以便在查看单个文档的结果时创建多个条目
现在我们将在map函数中多次使用
emit()。我们还将发出数组,将发票编号
和条形码
作为索引,如下所示:
var myIndex = {
_id: '_design/my_index',
views: {
'my_index': {
map: function (doc) {
for(var i=0, length=doc.invoices.length; i<length; i++){
emit(
// emit array of invoiceNumber and barCode as key:
[doc.invoices[i].invoiceNumber, doc.invoices[i].barCode],
// emit array of clientId and clientName as value
// Actually, value can be whatever you want:
[doc.clientId, doc.clientName]
);
}
}.toString()
}
}
};
也来看看
pouch.put(myIndex).then(() => {
// query the index
return pouch.query('my_index', {key: ['12312313','1234324']});
}).then(result => {
// found docs with invoiceNumber === '12312313' and barCode === '1234324'
console.log('Result: ', result)
});