Questions tagged [mongodb-csharp-2.0]

Version 2.0 of the C# driver for MongoDB.

187 questions
9
votes
1 answer

New alternative for old .net Driver MongoCollection.Save?

I have some C# code which uses the old 1.x version of MongoDB driver which offers a generic save method using the MongoCollection.Save() method. However after upgrading to 2.0 this method appears to be gone and replaced with an Update method which…
coolblue2000
  • 3,796
  • 10
  • 41
  • 62
8
votes
1 answer

MongoDb Driver 2 - Singleton Instance Resilience

Does anyone have any prior experience of working with the MongoDB C# Driver (v2+) with singleton style connection/collection instances in terms of connection resilience? The Problem We have recently made a push to secure our wider infrastructure,…
8
votes
1 answer

MongoDB C# Driver -- Create Index

I am using the MongoDB C# driver to create an index When my app starts up, it creates the index as below await collection.Indexes.CreateOneAsync(new BsonDocument("code", 1), new CreateIndexOptions() { Unique = true, Sparse = true }); My question is…
Mr.Wang from Next Door
  • 13,670
  • 12
  • 64
  • 97
7
votes
4 answers

MongoDB c# driver using upsert with updateMany

In MongoDB c# driver (2.0+) can we do an upsert when doing and updateManyAsync? This example helps with UpdateOne, but i am looking for something that works with updateMany.
asb
  • 781
  • 2
  • 5
  • 23
7
votes
3 answers

MongoDB Driver 2.0 C# is there a way to find out if the server is down? In the new driver how do we run the Ping command?

How do you call the Ping command with the new C# driver 2.0? In the old driver it was available via Server.Ping()? Also, Is there a way to find out if the server is running/responding without running the actual query? Using…
7
votes
2 answers

Get generated script in MongoDB C# driver

I am using MongoDB.Driver 2.0.0. Is there any way to see a generated script from linq to MongoDB? For example my query is like: IFindFluent findFluent = Collection.Find( x => hashValues.Contains(x.UrlHash) &&…
Teoman shipahi
  • 47,454
  • 15
  • 134
  • 158
5
votes
0 answers

Find nearest latitude/longitude in a DB collection with C# MongoDB query

I have a MongoDB collection which holds millions of records like below { "_id" : ObjectId("5e662d6e9ce8bf144c715afd"), "X" : 19.229000091552734, "Y" : 233.723388671875, "Data" : { // Some data } } { "_id" :…
HaBo
  • 13,999
  • 36
  • 114
  • 206
5
votes
1 answer

MongoDB: Trouble with child class with an overridden ID and attribute

I'm having big problems when I'm overriding the Id property in a derived class in my MongoDB storage setup. The base class that all of my data models inherit looks like this: public abstract class DataModel { [BsonId] …
silkfire
  • 24,585
  • 15
  • 82
  • 105
5
votes
2 answers

How to Insert document to MongoDB and return the same document or it's ID back using InsertOneAsync in C# .Net

I'm writing a generic method to act like data access layer to insert document to MongoDB using C# .Net. My method looks like below. Collection here is a MongoCollection retrieved from MongoDB. public async T Create(T entity){ await…
Aravind
  • 462
  • 1
  • 7
  • 22
5
votes
1 answer

c# mongo 2.0 driver get item after FindOneAndUpdateAsync

I have the following query in c#: var filter = Builders.Filter.And( Builders.Filter.Eq(n => n.UserId, userId), …
Ori Refael
  • 2,888
  • 3
  • 37
  • 68
5
votes
1 answer

Mongo C# driver 2.0 - Find count without fetching documents

A general count query will be doing a int count = collection.Find(filter).Count(); Now that loads all the records as per the filter, so lets says I have 1 million records and out of those 0.5 million match my filter, so I'll have collection…
Mr767267
  • 1,008
  • 2
  • 11
  • 18
5
votes
1 answer

How to create a fluent Aggregation using MongoDB C# Driver 2.0

I'm quite new to MongoDB and I'm using it in a Web Api to serve a mobile application. Now, I need to run an aggregation and since I'm using C#, I would like to do it fluently by using the Aggregate command on a collection which returns me an…
Complexity
  • 5,682
  • 6
  • 41
  • 84
5
votes
1 answer

Update field in array mongodb c# driver

I try to update status field for object from p2l array var update = Builders.Update.Set("p2l.$.status",BsonValue.Create(status)) It seems that code will work fine, but how to implement it with typed builder and set all fields with…
Vladyslav Furdak
  • 1,765
  • 2
  • 22
  • 46
5
votes
4 answers

Insert new document using InsertOneAsync (.NET Driver 2.0)

In the older .Net API version : MongoClient client = new MongoClient(); var server = client.GetServer(); var db = server.GetDatabase("foo"); var collection = db.GetCollection("bar"); var document = new BsonDocument { { "_id", 1 }, {…
Hana
  • 824
  • 4
  • 14
  • 30
4
votes
1 answer

How to join multiple collections using Mongodb C# driver

I need to join 3 collections in aggregation with multiple $lookup I tried in C# driver it allow me to $lookup User collection but can't perform second $lookup for Setting collection. Anyone can help? db.Transactions.aggregate([ { …
codecodeNinja
  • 176
  • 2
  • 3
  • 15
1 2
3
12 13