How to delete all mongo documents in c# within particular time span

I’m trying to delete mongo document from particular collection in c#

how i’m trying now is

            var document = collection.Find(_ => true).FirstOrDefault();  //get all the document              foreach (var item in (dynamic)document)             {                 if (item.Timestamp >= "")                 {                     if ("Some Date" > Convert.ToDateTime(item.Timestamp))                     {                         collection.DeleteOne(item);   //delete document one by one                     }                 }             } 

here i’m trying get all the document and delete one by one but there will be lot of documents to delete it can affect to performance so is there any way to direct delete mongo documents instead of get and delete in c#

Add Comment
0 Answer(s)

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.