如何删除Couch db中的文档 [英] How to delete docs in Couch db

查看:55
本文介绍了如何删除Couch db中的文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过使用

function(doc) {
    var startdate= new Date(doc.Date);
    var enddate= new Date("July 12, 2013 11:13:00");
    if(startdate < enddate){
        emit([startdate, enddate], doc._id);
        doc.remove();
    }
}

我正在获取结果,但是无法删除它们,是的,我已经在数据库的临时视图中使用了这段代码

I am getting the results, but not able to delete them and yes I have used this code in the temp view of the database

推荐答案

您要执行的操作是批量删除.不能像您尝试的那样从视图中完成操作.我建议您先阅读CouchDB文档,以了解如何进行常规的CRUD操作.

What you're trying to do is bulk delete. It cannot be done from a view, like you tried it. I recommend you read the CouchDB documentation first, to see how normal CRUD operations are made.

如果您想跳过该步骤(不建议这样做,但有时我们会很急),请检查以下问题:

If you want to skip that step(not recommended but we're all in a hurry sometimes) then check this SO question: How can I delete multiple documents in CouchDB?. It's the same problem as yours.

很抱歉为您解决此问题,但是对这个问题没有简单的答案.但我将尝试概述此任务所需的逻辑:

I'm sorry to break it for you, but there's no easy answer to this problem. But I'll try to outline the logic required for this task:

  1. 根据您的视图逻辑检索您要删除"的文档
  2. 对文档中的_delete字段进行批量更新,并将其设置为true(_delete = true)http://wiki.apache.org/couchdb/HTTP_Bulk_Document_API
  3. 详细了解删除对CouchDB的含义: http://n.exts.ch/2012/11/baleting http://docs.couchdb.org/en/latest/api/database/misc.html

祝你好运!

这篇关于如何删除Couch db中的文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆