Javascript {错误:';未找到';,原因:';已删除';,名称:';未找到';,状态:404,消息:';已删除';}
我正在构建一个CouchDB设计文档,如下所示:Javascript {错误:';未找到';,原因:';已删除';,名称:';未找到';,状态:404,消息:';已删除';},javascript,view,couchdb,Javascript,View,Couchdb,我正在构建一个CouchDB设计文档,如下所示: const ddoc={ "_id":"_design/index2nd", "views":{ "by_id":{ "map": (function(doc){emit(doc._id, doc);}).toString() }, "by_username":{ "map": (function(doc){emit(doc.usern
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)
})
但是,我收到以下错误:
错误:未生成index2nd/by_id:{错误:“未找到”,
原因:“已删除”,
名称:“未找到”,
现状:404,
消息:“已删除”}
错误:未生成index2nd/by_用户名:{错误:“未找到”,
原因:“已删除”,
名称:“未找到”,
现状:404,
消息:“已删除”}
最后,我通过使用
buckdb-upsert
插件解决了这个问题。参考和
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)
})