Questions tagged [mongodb-csharp-2.0]

Version 2.0 of the C# driver for MongoDB.

187 questions
50
votes
3 answers

Get All 'documents' from MongoDB 'collection'

I need to retrieve all the documents that are in my collection in MongoDB, but I cannot figure out how. I have declared my 'collection' like this- private static IMongoCollection SpeCollection =…
NicolasR
  • 874
  • 2
  • 11
  • 18
43
votes
4 answers

MongoDB C# Driver 2.0 - Update document

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 =…
Alessandro Di Lello
  • 1,181
  • 1
  • 9
  • 22
42
votes
4 answers

MongoDb c# driver find item in array by field value

i found the way to check is the value contains in simple array : var filter = Builders.Filter.AnyEq(x => x.Tags, "mongodb"); But how to find a complex item with many fields by a concrete field ? I found the way to write it via the dot…
Vladyslav Furdak
  • 1,765
  • 2
  • 22
  • 46
35
votes
2 answers

Difference between Find and FindAsync

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
object88
  • 720
  • 1
  • 7
  • 20
33
votes
4 answers

BsonSerializationException when serializing a Dictionary to BSON

I've recently moved to the new MongoDB C# driver v2.0 from the deprecated v1.9. Now, when I serialize a class that has a dictionary I sometimes run into the following BsonSerializationException: MongoDB.Bson.BsonSerializationException: When using…
i3arnon
  • 113,022
  • 33
  • 324
  • 344
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
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
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
24
votes
5 answers

How do I resume a MongoDB ChangeStream at the first document and not just changes after I start listening

My goal for this app is to create logic that monitors the database and will trigger actions when a document is added to the database (like sending an email). However, since this application may not be started when a database is first populated, how…
Jerren Saunders
  • 1,188
  • 1
  • 8
  • 26
24
votes
3 answers

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

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…
Shy Peleg
  • 605
  • 1
  • 6
  • 9
20
votes
3 answers

How do I log my queries in MongoDB C# Driver 2.0?

Just upgraded my application to the latest stable MongoDB C# Driver 2.0. During the migration, basic functionality has been broken and even the simplest query like: this.collection.Find(e => e.Id == id).SingleOrDefaultAsync() doesn't return the…
Shay
  • 1,680
  • 2
  • 26
  • 39
19
votes
2 answers

Paging MongoDB query with C# drivers

I am using version 2.2 of MongoDB drivers for C#. I want to paginate a query : the response to the query must contain the items of the current page and the total count of items matching the query. I want to do one query. With the mongo shell I can…
gentiane
  • 6,715
  • 3
  • 23
  • 34
18
votes
1 answer

Query with filter builder on nested array using MongoDB C# driver

Consider the following object structure stored as documents: public class Foo { public string Id { get; set; } public ICollection Bars { get; set; } // ... } public class FooBar { public string BarId { get; set; } //…
kspearrin
  • 10,238
  • 9
  • 53
  • 82
17
votes
1 answer

MongoDB C# driver 2.0 InsertManyAsync vs BulkWriteAsync

I have to insert many documents in a MongoDB collection, using the new C# 2.0 driver. Is using either collection.InsertManyAsync(...) or collection.BulkWriteAsync(...) making any difference? (particularly about performance). From what I understand…
Stefano Castriotta
  • 2,823
  • 3
  • 16
  • 26
14
votes
4 answers

FindAll in MongoDB .NET Driver 2.0

I want to query my MongoDB collection without any filter with MongoDB .NET Driver 2.0 but I didn't find a way. I have the following workaround but it looks weird :D var filter = Builders.Filter.Exists(x => x.Id); var fooBars = await…
tugberk
  • 57,477
  • 67
  • 243
  • 335
1
2 3
12 13