ravendb / ravendb

ACID Document Database
https://ravendb.net
Other
3.55k stars 820 forks source link

Deleting a collection including HiLo #18958

Closed ssteiner closed 1 month ago

ssteiner commented 1 month ago

I've found examples for RavenDb 3.5 on Stackoverflow - but 3.5 uses another syntax which is no longer supported.

This is where I'm at now - it gets rid of all documents on one collection, but doesn't delete the Hilo entry

internal static void DeleteCollection(string collectionName, IDocumentSession session, IDocumentStore store)
{
    var deleteByQueryOp = new DeleteByQueryOperation($"from '{collectionName}'");
    var operation = store.Operations.Send(deleteByQueryOp);
    var result = operation.WaitForCompletion<BulkOperationResult>(TimeSpan.FromSeconds(15));
    var hiloKey = $"Raven/H‌​ilo/{collectionName}";
    if (session.Advanced.Exists(hiloKey))
    {
        session.Delete(hiloKey);
    }
}

How would I get rid of the HiLo so as to really clean up everything?

ayende commented 1 month ago

The @hilo document don't belong to the collection (they belong to the @hilo collection), you can just delete them directly by name.

This is because you don't want to get the hilo document when you query from Users, for example.

Your problem is if (session.Advanced.Exists(hiloKey)) just issue the Delete unconditionally, and remember to call SaveChanges