couchdb-net icon indicating copy to clipboard operation
couchdb-net copied to clipboard

FindManyAsync returns deleted documents, but not sure how to identify them?

Open broomfn opened this issue 2 years ago • 8 comments

FindManyAsync seems to return deleted documents, Is there currently a way to identify if the document is deleted or not?

If not would it be possible to expose _deleted=true on the CouchDocument for example.

Thanks

broomfn avatar Nov 23 '21 18:11 broomfn

Hi, that's a tricky one. Is that correct that the DB returns deleted documents in the first place?

matteobortolazzo avatar Nov 23 '21 21:11 matteobortolazzo

The FindManyAsync method, uses the _bulk_get CouchDB endpoint, if I use Thunder Client/Postman and pass a deleted document id, such as:

{
    "docs": [
        {
            "id": "rb-ct002110:017d33dd6cf4476f9e6e8604fd436c73"
        }
    ]
}

I get the following result:

{
  "results": [
    {
      "id": "rb-ct002110:017d33dd6cf4476f9e6e8604fd436c73",
      "docs": [
        {
          "ok": {
            "_id": "rb-ct002110:017d33dd6cf4476f9e6e8604fd436c73",
            "_rev": "2-8006f354c92f25ef9cf4aa630fac35fc",
            "_deleted": true
          }
        }
      ]
    }
  ]
}

broomfn avatar Nov 24 '21 10:11 broomfn

I trust you, what I am saying, can it be a CouchDB bug or missing setting on DB level?

I am asking because it's not documented on their end

matteobortolazzo avatar Nov 24 '21 21:11 matteobortolazzo

I'm guessing it's by design, but poorly documented, there's some information on the _delete flag here:

https://docs.couchdb.org/en/stable/api/document/common.html#get--db-docid https://docs.couchdb.org/en/stable/ddocs/ddocs.html https://docs.couchdb.org/en/stable/replication/conflicts.html https://docs.couchdb.org/en/stable/api/database/misc.html

The most convincing bit would probably be the first link where it documents the GET /{db}/{docid} endpoint and describes the flag as _deleted (boolean) – Deletion flag. Available if document was removed.

However, further down the document the following section seem to suggest you need to supply a rev to retrieve the deleted document (I've not tried this, so I can't confirm, but if that is the case then maybe the _bulk_get function is suppose to work the same way and there is a genuine bug with it?):

https://docs.couchdb.org/en/stable/api/document/common.html#retrieving-deleted-documents

broomfn avatar Nov 25 '21 15:11 broomfn

https://github.com/apache/couchdb/discussions/3849

broomfn avatar Nov 25 '21 15:11 broomfn

https://github.com/apache/couchdb/issues/3608#issuecomment-873263210

broomfn avatar Nov 25 '21 19:11 broomfn

Hi,

I've added the following to properties to my document as a workaround until this gets fixed:

        // We add this property to detect deleted field returned from the _bulk_get endpoint
        // https://github.com/matteobortolazzo/couchdb-net/issues/154
        [JsonProperty("_deleted")]
        private bool NativeDeleted {
            set => Deleted = value;
        }

        [JsonIgnore]
        public bool Deleted { get; set; } = false;

broomfn avatar Nov 29 '21 15:11 broomfn

Hi, I think we can add a parameter to filter out delete documents

matteobortolazzo avatar Dec 03 '21 21:12 matteobortolazzo

It took a lot, but I added the property :)

matteobortolazzo avatar Oct 19 '22 23:10 matteobortolazzo