Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Mongo DeleteMany - without using a class

Tags:

c#

mongodb

I have a normal (not GridFS) collection in a MongoDB I need to access to and delete some documents. I want/need to do this without using a class.

Have tried a few things yesterday/today and searched the web alot and tried a number of things.

Can't work out why deletemany isn't working for me. I have tried so many things I deleted all the code I tried and want to start fresh.

Are there decent examples some one can share a link to? or maybe some code example just here?

Thanks Russell

like image 960
yogibear Avatar asked Oct 17 '25 03:10

yogibear


1 Answers

the following would be the most convenient way. it uses the implicit operator to convert json string to filterdefinition. so no need for a class.

    var collection = new MongoClient("mongodb://localhost")
                        .GetDatabase("test")
                        .GetCollection<object>("person");

    collection.DeleteMany("{ name : 'John Doe' }");
like image 124
Dĵ ΝιΓΞΗΛψΚ Avatar answered Oct 18 '25 17:10

Dĵ ΝιΓΞΗΛψΚ