Indexing Pouch db multi dimensional documents

后端 未结 1 528
醉酒成梦
醉酒成梦 2021-01-15 13:48

Looking for a way to index pouchDB

Can\'t find a way to index when i have multiple dimensions

Here is my document client example

Note that client

1条回答
  •  别那么骄傲
    2021-01-15 14:37

    As mentioned on CouchDB documentation:

    ... the emit() function can be called multiple times in the map function to create multiple entries in the view results from a single document...


    Now we are going to use emit() multiple times in the map function. Also we are going to emit arrays to have both invoiceNumber and barCode as the index, like this:

    var myIndex = {
        _id: '_design/my_index',
        views: {
            'my_index': {
                map: function (doc) {
                    for(var i=0, length=doc.invoices.length; i

    Now lets PUT our above design document and query it with PouchDB:

    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)
    });
    

    Also take a look at this similar answer.

    0 讨论(0)
提交回复
热议问题