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
112
votes
11 answers

How to replace substring in mongodb document

I have a lot of mongodb documents in a collection of the form: { .... "URL":"www.abc.com/helloWorldt/..." ..... } I want to replace helloWorldt with helloWorld to get: { .... "URL":"www.abc.com/helloWorld/..." ..... } How can I achieve this for…
user1071979
  • 1,701
  • 2
  • 12
  • 25
106
votes
8 answers

Redirect output of mongo query to a csv file

I am using MongoDB 2.2.2 for 32-bit Windows7 machine. I have a complex aggregation query in a .js file. I need to execute this file on the shell and direct the output to a CSV file. I ensure that the query returns a "flat" json (no nested keys), so…
Aafreen Sheikh
  • 4,949
  • 6
  • 33
  • 43
89
votes
9 answers

Storing Enums as strings in MongoDB

Is there a way to store Enums as string names rather than ordinal values? Example: Imagine I've got this enum: public enum Gender { Female, Male } Now if some imaginary User exists with ... Gender gender = Gender.Male; ... it'll be stored…
Kostassoid
  • 1,870
  • 2
  • 20
  • 29
89
votes
7 answers

Truncate a collection

How do I truncate a collection in MongoDB or is there such a thing? Right now I have to delete 6 large collections all at once and I'm stopping the server, deleting the database files and then recreating the database and the collections in it. Is…
iefpw
  • 6,816
  • 15
  • 55
  • 79
88
votes
4 answers

How to get the Mongo database specified in connection string in C#

I would like to connect to the database specified in the connection string, without specifying it again in GetDatabase. For example, if I have a connection string like this; mongodb://localhost/mydb I would like to be able to…
Pete Montgomery
  • 4,060
  • 3
  • 30
  • 40
78
votes
3 answers

MongoDB C# Driver - Ignore fields on binding

When using a FindOne() using MongoDB and C#, is there a way to ignore fields not found in the object? EG, example model. public class UserModel { public ObjectId id { get; set; } public string Email { get; set; } } Now we also store a…
LiamB
  • 18,243
  • 19
  • 75
  • 116
73
votes
6 answers

.NET best practices for MongoDB connections?

I've been playing with MongoDB recently (It's AMAZINGLY FAST) using the C# driver on GitHub. Everything is working just fine in my little single threaded console app that I'm testing with. I'm able to add 1,000,000 documents (yes, million) in under…
68
votes
3 answers

MongoDB GridFs with C#, how to store files such as images?

I'm developing a web app with mongodb as my back-end. I'd like to have users upload pictures to their profiles like a linked-in profile pic. I'm using an aspx page with MVC2 and I read that GridFs library is used to store large file types as…
EKet
  • 7,272
  • 15
  • 52
  • 72
63
votes
3 answers

Convert string into MongoDB BsonDocument

I have a long string in JSON format, and I want to convert it into a BSONDocument for insertion into a MongoDB database. How do I do the conversion? I'm using the official C# driver.
Journeyman
  • 10,011
  • 16
  • 81
  • 129
63
votes
8 answers

How do you update multiple field using Update.Set in MongoDB using official c# driver?

The following code will allow me to update the Email where FirstName = "john" and LastName = "Doe". How do you update both Email and Phone without using Save() method? MongoDB.Driver.MongoServer _server =…
atbebtg
  • 4,023
  • 9
  • 37
  • 49
63
votes
6 answers

How to create indexes in MongoDB via .NET

I've programmatically created a new document collection using the MongoDB C# driver. At this point I want to create and build indexes programmatically. How can I do that?
Payedimaunt
  • 1,014
  • 2
  • 10
  • 23
55
votes
3 answers

How to find min value in mongodb

How do you do the equivalent of SELECT MIN(Id) AS MinId FROM Table with MongoDB? It looks like I will have to use MapReduce but I can't find any example that shows how to do this.
atbebtg
  • 4,023
  • 9
  • 37
  • 49
55
votes
5 answers

MongoDB C# Driver: Ignore Property on Insert

I am using the Official MongoDB C# Drive v0.9.1.26831, but I was wondering given a POCO class, is there anyway to ignore certain properties from getting inserted. For example, I have the following class: public class GroceryList { public string…
Abe
  • 6,386
  • 12
  • 46
  • 75
53
votes
11 answers

MongoDB and C#: Case insensitive search

I am using MongoDB and the C# driver for MongoDB. I recently discovered that all queries in MongoDB are case-sensitive. How can I make a case-insensitive search? I found one way to do this: Query.Matches( "FirstName", …
Andrew Orsich
  • 52,935
  • 16
  • 139
  • 134
52
votes
9 answers

Element 'Id' does not match any field or property of class

I got the result from the collection in MongoDB, the structure is the same as below [DataContract] public class Father { [BsonId] [DataMember] public MongoDB.Bson.ObjectId _id { get; set; } [DataMember] public string Id { get;…
EasonBlack
  • 4,196
  • 4
  • 21
  • 24
1
2 3
99 100