【问题标题】:{ error: 'not_found', reason: 'deleted', name: 'not_found', status: 404, message: 'deleted' }{ 错误:'not_found',原因:'已删除',名称:'not_found',状态:404,消息:'已删除'}
【发布时间】:2017-02-01 16:16:08
【问题描述】:

我正在构建一个这样的 CouchDB 设计文档:

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 未构建:{ 错误:'not_found', 原因:'删除', 名称:'not_found', 状态:404, 消息:“已删除”}

错误:index2nd/by_username 未构建:{ 错误:'not_found', 原因:'删除', 名称:'not_found', 状态:404, 消息:“已删除”}

【问题讨论】:

    标签: javascript view couchdb


    【解决方案1】:

    最后我通过使用pouchdb-upsert 插件解决了这个问题。参考thisthat

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-07-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-10
      • 1970-01-01
      相关资源
      最近更新 更多