Version 2.0 of the C# driver for MongoDB.
Questions tagged [mongodb-csharp-2.0]
187 questions
14
votes
1 answer
Unwind then Group aggregation in MongoDB C#
I'm having some trouble with the new C# 2.0 MongoDB driver and the aggregation pipeline.
Basically, I'm trying to return the most popular elements within an array field on the object. The field type is: IList FavouritePlaceIds { get; set;…

Juzzbott
- 1,737
- 2
- 25
- 44
12
votes
6 answers
Mongo C# driver - Contains Filter
I am using the latest version of Mongo C# driver which uses a lot of Async and builder pattern. Which is nice. I am trying to convert SQL where clauses into Mongo FilterDefinition object.
Any idea how to handle "contains"?
like:
where x contains…

Mr767267
- 1,008
- 2
- 11
- 18
12
votes
4 answers
Getting a single object from mongodb in C#
I've picked up a piece of code that is using the MongoDB driver like this to get a single object from a collection...this can't be right, can it? Is there a better way of getting this?
IMongoCollection…

Paul
- 9,409
- 13
- 64
- 113
12
votes
1 answer
How to do an upsert with MongoDB 2.0?
The interface of MongoDB has completely changed from the previous one.
Here you can see the official documentation with some examples about how to search, insert and update but what about upserts?
Idea for meta: I've tried to search on google and…

Revious
- 7,816
- 31
- 98
- 147
12
votes
4 answers
MongoDB C# 2.0 TimeoutException
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…

Serhat Ozgel
- 23,496
- 29
- 102
- 138
12
votes
1 answer
C# MongoDB.Driver GetServer is Gone, What Now?
From the mongoDB.Driver docs (http://docs.mongodb.org/ecosystem/tutorial/getting-started-with-csharp-driver/)
Get a Reference to a Server Object
To get a reference to a server object from the client object, write this:
var server =…

MoonKnight
- 23,214
- 40
- 145
- 277
11
votes
1 answer
When I use ReplaceOneAsync and IsUpsert = true mongodb add's a null Id. How do I stop this?
I am able to update a Document if the Document Exists using the Following
var filter = Builders.Filter.Eq(x => x.Id, neighborhood.Id);
var result = await collection.ReplaceOneAsync(filter,
neighborhood,new UpdateOptions {…

SPS101
- 278
- 1
- 4
- 12
11
votes
1 answer
Initialize MongoClient with MongoClientSettings in C#
I'm trying to initialize the MongoClient from the Mongo 2.0 driver as follows:
MongoClientSettings settings = new MongoClientSettings();
settings.WaitQueueSize = int.MaxValue;
settings.WaitQueueuTimeout = new…

Fedor Finkenflugel
- 335
- 1
- 4
- 15
11
votes
2 answers
Understanding the changes in MongoDB new C# driver (Async and Await)
The new C# driver is totally Async and in my understanding twists a little bit the old design patterns such as DAL in n-tier architecture.
In my Mongo DALs I use to do:
public T Insert(T entity){
_collection.Insert(entity);
return…

SexyMF
- 10,657
- 33
- 102
- 206
10
votes
2 answers
MongoDB FilterDefinition & IQueryable in C#
I have the following spatial FilterDefinition:
var filter = Builders
.Filter
.Near(x => x.Point, point, 1000);
Is there any way to include this into an IQueryable expression?
For example, I might have…

Dave New
- 38,496
- 59
- 215
- 394
10
votes
2 answers
MongoDb c# official driver bulk update
How can i rewrite the following old code via the new C# MongoDb driver which using IMongoCollection interface :
var bulk = dbCollection.InitializeUnorderedBulkOperation();
foreach (var profile in profiles)
{
…

Vladyslav Furdak
- 1,765
- 2
- 22
- 46
10
votes
1 answer
Building indexes in MongoDB with .NET driver 2.0
What's the new way to build indexes with the new driver 2.0?
There's no documentation whatsoever about this.
Apparently this now works with the new IndexKeysDefinitionBuilder<> interface but that's all I got so far.

hholtij
- 2,906
- 6
- 27
- 42
9
votes
1 answer
How to set MongoDB Change Stream 'OperationType' in the C# driver?
When running the new MongDB Server, version 3.6, and trying to add a Change Stream watch to a collection to get notifications of new inserts and updates of documents, I only receive notifications for updates, not for inserts.
This is the default way…

Michael Westberg
- 93
- 1
- 7
9
votes
1 answer
Create a text index for fields in array using an expression
I want to create a text index for multiple fields and fields of elements in an array. Currently I define the path to the array elements as a string, which works. Is there a way to use an expression just like I can do for simple fields like this:
var…

hansmaad
- 18,417
- 9
- 53
- 94
9
votes
1 answer
MongoDb Count after aggregation C# 2.0 driver
I have the following aggregation pipline
var count = dbCollection.
Aggregate(new AggregateOptions { AllowDiskUse = true }).Match(query).
Group(groupby).
ToListAsync().Result.Count();
And this gets the following result:
{
"result" : [
…

Vladyslav Furdak
- 1,765
- 2
- 22
- 46