mongodb-csharp-2.0

MongoDB C# Driver 2.0 - Update document

吃可爱长大的小学妹 提交于 2019-11-27 13:30:30
I'm currently upgrading my code to MongoDB C# driver 2.0 and I'm having issues upgrading the code to update documents. using the old version I was able to do something like this: MyType myObject; // passed in var collection = _database.GetCollection<MyType>("myTypes"); var result = collection.Save(myObject); I'm struggling to find a way to do this in the new version. I have found a few examples of updating single fields like var filter = Builders<MyType>.Filter.Eq(s => s.Id, id); var update = Builders<MyType>.Update.Set(s => s.Description, description); var result = await collection

Translate FilterDefinition<TDocument> to regular json mongo query that i can run in a mongo shell

拈花ヽ惹草 提交于 2019-11-27 13:01:13
问题 I have many complex queries that I sometimes wish to check directly against Mongo for debugging \ explaining() purposes. With the newer 2.0+ c# driver, i'm not sure how to do this. With the previous version there was a thing called IMongoQuery and This worked. A simple example: FilterDefinition<LalalaEvent> filter = Builders<LalalaEvent>.Filter .Where(e => ids.Contains(e.Id) && e.Deleted != true ); 回答1: If you're using the latest version of the driver, which is 2.0.1 you can easily put that

Difference between Find and FindAsync

寵の児 提交于 2019-11-27 05:46:27
问题 I am writing a very, very simple query which just gets a document from a collection according to its unique Id. After some frusteration (I am new to mongo and the async / await programming model), I figured this out: IMongoCollection<TModel> collection = // ... FindOptions<TModel> options = new FindOptions<TModel> { Limit = 1 }; IAsyncCursor<TModel> task = await collection.FindAsync(x => x.Id.Equals(id), options); List<TModel> list = await task.ToListAsync(); TModel result = list

MongoDB C# 2.0 TimeoutException

∥☆過路亽.° 提交于 2019-11-26 23:15:55
We've recently upgraded our web application to MongoDB C# Driver 2.0 and deployed to production. Below a certain load, the application runs fine. Once the load on the production server exceeds a certain limit, the CPU of the application instantly falls down to 0 and after about 30 seconds, this exception is logged several times: System.TimeoutException message: A timeout occured after 30000ms selecting a server using CompositeServerSelector{ Selectors = ReadPreferenceServerSelector{ ReadPreference = { Mode = Primary, TagSets = System.Collections.Generic.List`1[MongoDB.Driver.TagSet] } },

MongoDB C# Driver 2.0 - Update document

感情迁移 提交于 2019-11-26 16:25:42
问题 I'm currently upgrading my code to MongoDB C# driver 2.0 and I'm having issues upgrading the code to update documents. using the old version I was able to do something like this: MyType myObject; // passed in var collection = _database.GetCollection<MyType>("myTypes"); var result = collection.Save(myObject); I'm struggling to find a way to do this in the new version. I have found a few examples of updating single fields like var filter = Builders<MyType>.Filter.Eq(s => s.Id, id); var update =

MongoDB C# 2.0 TimeoutException

梦想的初衷 提交于 2019-11-26 08:37:35
问题 We\'ve recently upgraded our web application to MongoDB C# Driver 2.0 and deployed to production. Below a certain load, the application runs fine. Once the load on the production server exceeds a certain limit, the CPU of the application instantly falls down to 0 and after about 30 seconds, this exception is logged several times: System.TimeoutException message: A timeout occured after 30000ms selecting a server using CompositeServerSelector{ Selectors = ReadPreferenceServerSelector{