2017-01-31 15 views
0

Я строю CouchDB дизайн документ так:{ошибка: 'not_found', причина: 'удалено', название: 'not_found', состояние: 404, сообщение: 'удалено'}

const ddoc={ 
    "_id":"_design/index2nd", 
    "views":{ 
     "by_id":{ 
      "map": (function(doc){emit(doc._id, doc);}).toString() 
     }, 
     "by_username":{ 
      "map": (function(doc){emit(doc.username, doc);}).toString() 
     } 
    } 
} 

Я спасаю дизайн док с этим:

db.put(ddoc).then(()=>{ 
    ////done! 
}).catch(err=>{ 
    console.log('error: design doc is not saved: ', err) 
}) 

индекс не построен до тех пор, пока запрос его, поэтому я пустой запрос, чтобы начать новую сборку:

db.query("index2nd/by_id",{ 
    limit:0 // don't return any results 
}).then(result=>{ 
    // index was built! 
}).catch(err=>{ 
    console.log('error: index2nd/by_id is not built: ', err) 
}) 

db.query("index2nd/by_username",{ 
    limit:0//don't return any results 
}).then(result=>{ 
    //index is built 
}).catch(err=>{ 
    console.log('error: index2nd/by_username is not built: ', err) 
}) 

Однако я получаю следующее сообщение об ошибке:

error: index2nd/by_id is not built: { error: 'not_found', reason: 'deleted', name: 'not_found', status: 404, message: 'deleted' }

error: index2nd/by_username is not built: { error: 'not_found', reason: 'deleted', name: 'not_found', status: 404, message: 'deleted' }

ответ

0

Наконец я решил проблему с помощью pouchdb-upsert плагина. См. this и that.

const ddoc={ 
    "_id":"_design/myIndex", 
    "views":{ 
     "by_id":{ 
      "map": (function (doc){emit(doc._id);}).toString() 
     }, 
     "by_username":{ 
      "map": (function (doc){emit(doc.username);}).toString() 
     } 
    } 
} 

PouchDB.plugin(require('pouchdb-upsert')) 

const diffFunc=doc=>{ 
    return ddoc;//always return the same ddoc 
} 

db.upsert('_design/myIndex',diffFunc).then(res=>{ 
    // happily done 
}).catch(err=>{ 
    console.log('error @ upsert: ', err) 
}) 

 Смежные вопросы

  • Нет связанных вопросов^_^