Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
broomfn opened this issue Nov 23, 2021 · 9 comments
Closed
Labels
question Further information is requested

Comments

@broomfn
Copy link

broomfn commented Nov 23, 2021

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

@matteobortolazzo
Copy link
Owner

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

@matteobortolazzo matteobortolazzo added the question Further information is requested label Nov 23, 2021
@broomfn
Copy link
Author

broomfn commented Nov 24, 2021

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

@matteobortolazzo
Copy link
Owner

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

@broomfn
Copy link
Author

broomfn commented Nov 25, 2021

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
Copy link
Author

broomfn commented Nov 25, 2021

apache/couchdb#3849

@broomfn
Copy link
Author

broomfn commented Nov 25, 2021

@broomfn
Copy link
Author

broomfn commented Nov 29, 2021

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;

@matteobortolazzo
Copy link
Owner

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

@matteobortolazzo
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants