0

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#

dev
  • 163
  • 1
  • 11
  • https://stackoverflow.com/questions/59160561/c-sharp-mongo-deletemany-without-using-a-class is this what are you looking for ? – WhiteRom Aug 03 '20 at 07:08
  • @WhiteRom something like this but with some time span. – dev Aug 03 '20 at 07:14
  • Is there any problem with adding filter (with TimeStamp field) inside deleteMany function ? Something like collection.DeleteMany({"Timestamp": {"$ne": ""}}) – WhiteRom Aug 03 '20 at 07:24

0 Answers0