Questions tagged [mongodb-.net-driver]

The official MongoDB .NET Driver provides asynchronous interaction with MongoDB.

MongoDB .NET Driver

The next generation .NET driver for MongoDB

Introduction

The official MongoDB .NET Driver provides asynchronous interaction with MongoDB. Powering the drivers is a Core library and a BSON library.

Features

  • Driver - A completely async driver to talk with MongoDB.
  • GridFS - A distributed file system built on MongoDB.
  • Core Driver - The MongoDB Driver is built on top of a new Core library which anyone can use to build alternative or experimental high-level APIs.
  • BSON Library - A standalone BSON library, with a serialization infrastructure that you can use to build high-performance serializers.

MongoDB .NET Driver Documentation

2641 questions
30
votes
6 answers

How to remove one 'document' by 'ID' using the Official C# Driver for MongoDB?

Can someone please show me, if there is a better way to remove one document from MongoDB using the Official C# Driver than what I have below- var query = Query.EQ("_id", a.Id); database.GetCollection("Animal").Remove(query); This code…
Travis Laborde
  • 1,323
  • 1
  • 14
  • 22
30
votes
5 answers

MongoDB C# Query for 'Like' on string

i am using official mongodb c# driver. i want to query mongodb simliar to SQL Like something like db.users.find({name:/Joe/} in c# driver
gsagrawal
  • 2,900
  • 4
  • 27
  • 27
30
votes
3 answers

How is an IAsyncCursor used for iteration with the mongodb c# driver?

I'm trying to get a list of all the databases in my server and ultimately print them out (i.e. use their names as strings). With the previous version of the c# driver I could call the Server.GetDatabases(), but that has been replaced with…
Shamster
  • 2,092
  • 5
  • 24
  • 27
29
votes
4 answers

Unit of work in mongodb and C#

I know that MongoDB is not supposed to support unit of work, etc. But I think it would be nice to implement the repository which would store only the intentions (similar to criteria) and then commit them to the DB. Otherwise in every method in your…
Yurii Hohan
  • 4,021
  • 4
  • 40
  • 54
27
votes
6 answers

How to save date properly?

I'm trying to save date (using C# official driver): val = DateTime.Parse(value).Date; //Here date is {11/11/2011 12:00:00 AM} var update = Update.Set("Date", val); ... When I select Date from the database, the value is {11/10/2011 10:00:00 PM} How…
1gn1ter
  • 1,414
  • 2
  • 22
  • 47
27
votes
4 answers

Get only a specified field in MongoDB with C#

first time i'm using MongoDB. I have read this example: SELECT a,b FROM users WHERE age=33 db.users.find({age:33}, {a:1,b:1}) But I can't translate it into C#. Can anyone help me?
Daniele Tassone
  • 2,104
  • 2
  • 17
  • 25
27
votes
5 answers

Can I do a text query with the mongodb c# driver

Is there a way to submit a query that is expressed in the shell query syntax to the mongo c# driver For example Something like Coll.find { "myrecs","$query : { x : 3, y : "abc" }, $orderby : { x : 1 } } "); To take an example from the shell guide
pm100
  • 48,078
  • 23
  • 82
  • 145
27
votes
3 answers

C# mongodb driver 2.0 - How to upsert in a bulk operation?

I migrated from 1.9 to 2.2 and reading the documentation I was surprised to discover that is not possible to upsert during a bulk operation anymore, since operations don't allow options. bulkOps.Add(new UpdateOneModel(filter,…
Adrian Lopez
  • 2,601
  • 5
  • 31
  • 48
27
votes
4 answers

How to improve MongoDB insert performance

The result: If you are operating on a dataset that is fault tolerant, or doing a one time process you can verify, changing WriteAcknowledge to Unacknowledged can help. Also, bulk operations are IsOrdered by default, which I was not aware off.…
James
  • 2,458
  • 3
  • 26
  • 50
27
votes
3 answers

Update all properties of object in MongoDb

I'm using the MongoDB .Net driver in my project. I want to update all of the properties of my object that is stored in MongoDB. In the documentation, update is shown like this: var filter = Builders.Filter.Eq("i", 10); var update =…
Sefa
  • 8,865
  • 10
  • 51
  • 82
27
votes
2 answers

How to delete multiple ids in mongodb?

{ "_id" : ObjectId("51ee3966e4b056fe8f074f48"), "userid" : "66", "clientid" : "88", "deviceid" : "22", "timestamp" : "1374214822000"} { "_id" : ObjectId("51ee507ae4b056fe8f074f4a"), "userid" : "66", "clientid" : "88", "deviceid" : "22", "timestamp"…
user1983299
  • 393
  • 1
  • 5
  • 16
27
votes
3 answers

What is the right way to manage MongoDB connections in ASP.Net MVC?

What is the best practice for managing the MongoServer class life cycle? Should I create one and close it at the end of each request or should it be kept as a singleton for the entire life of the app using something like StructureMap? Any help is…
Roman
  • 10,309
  • 17
  • 66
  • 101
26
votes
6 answers

How to do findAll in the new mongo C# driver and make it synchronous

I was using official C# driver to do a FindAll and upgraded to the new driver 2.0. FindAll is obsolete and is replaced with Find. I am trying to convert a simple method that returns me a list of Class1. Cant find a realistic example using a POCO in…
Kar
  • 485
  • 1
  • 4
  • 9
26
votes
7 answers

What is the most mature MongoDB driver for C#?

So, there are mongodb-csharp simple-mongodb NoRM as C# drivers for MongoDB available. Which one of them is the most mature and stable one? Why would you choose one over the other two? Are they production ready?
Markus Dulghier
  • 1,580
  • 1
  • 17
  • 20
25
votes
1 answer

C# MongoDB Driver - How to use UpdateDefinitionBuilder?

I looked up a way to work with mongodb's UpdateDefinitionBuilders but the documentation doesn't really show much... I need to be able to dynamically build my update queries, so I thought about doing it like this: var update =…
Liran Friedman
  • 4,027
  • 13
  • 53
  • 96