Questions tagged [mongodb.driver]

The official MongoDB C#/.NET Driver provides asynchronous interaction with MongoDB.

About

For the official MongoDB C#/.NET documentation, see the MongoDB C#/.NET Documentation. For the API documentation, see MongoDB C# API Documentation.

Driver Features

  • MongoDB Driver

An updated .NET driver offering a full asynchronous stack. For documentation on the update .NET driver, see MongoDB C#/.NET Driver documentation.

  • BSON Library

A standalone BSON library with a serialization infrastructure that you can use to build high-performance serializers. For documentation on the BSON library, see BSON Reference.

  • Core Library

A new core library upon which MongoDB .NET Driver is built. Users can use the new core library to build alternative or experimental high-level APIs. For documentation on the core library, see Driver Core

Source

45 questions
15
votes
1 answer

C# mongodb driver 2.2.3 how to set batchSize for cursor

I am using official C# driver for MongoDB 2.2.3 How can I set batch size for the cursor using the C# driver? With javascript I can create a cursor and set batch size for it: var cursor = db.statistics.find(query).batchSize(100) and I can iterate…
denisvlah
  • 434
  • 1
  • 4
  • 13
8
votes
2 answers

How to get connection status in the C# MongoDB driver v2.0?

We are starting using new MongoDB driver v2 and we can't understand whether we are connected to the db or not. Our repository code: var client = new MongoClient("mongodb://{wrong-host}:{wrong-port}/{dbbname}"); var database =…
user854301
  • 5,383
  • 3
  • 28
  • 37
6
votes
2 answers

Get all items where subDocument.value in listOfStrings

I am using the MongoDB.Driver nuget package in dotnetcore 2.1. I am trying to return a list of documents in a collection where a subdocument field is equal to any items contained within a list that I have. Ideally I need this in C# syntax for the…
Jerrod Horton
  • 1,605
  • 1
  • 15
  • 30
6
votes
2 answers

How to read data from Mongodb which have duplicate element name in c#

I am using MongoDB.Drivers in my C# MVC application to communicate with Mongodb database. C# Code var client = new MongoClient("mongodb://localhost:27012"); var db = client.GetDatabase("Test_DB"); var collection =…
prog1011
  • 3,425
  • 3
  • 30
  • 57
5
votes
2 answers

MongoDB hosted in Azure Cosmos DB: Sharding vs partitioning

We want to use MongoDB for our database, and we want to use the MongoDB API to avoid to be "locked in" to Azure Cosmos DB hosting. We use .Net Core and the MongoDB.Driver package (to be able to easily switch between on-prem, Atlas, Azure Cosmos…
5
votes
1 answer

MongoDb / C# filter and get all subdocuments

I'm having difficulties querying a Mongo-DB collection. The document I'm using public class Customer { public ObjectId Id { get; set; } public int CustomerId { get; set; } public List
Addresses { get; set; } } public class…
Daniel Haefliger
  • 88
  • 1
  • 1
  • 6
4
votes
1 answer

Mapping BsonDocument to class but getting error

This is my BsonDocument that I extract from my MongoDb collection. I would like to deserialize (or map) this to an object/class that I made in C#. { "_id" : ObjectId("5699715218a323101c663b9a"), "type": null, "text": "Hello this is text", …
3
votes
1 answer

MongoDB C# Driver - how to enforce projection on the joined collection in .NET?

Here's the code: ProjectionDefinition projDefAccountant = Builders.Projection .Include(x => x.Id) .Include(x => x.Name); ProjectionDefinition projDefClient =…
3
votes
0 answers

Timeout exception on .net 4.6.1 but not on .net core 2.0 while connecting to mongodb using MongoDB.Driver

When using MongoDB.Driver (v2.9.1) in a project on visual studio 2017 with .net framework 4.6.1, running an aggregate command on a collection times out with the following exception: A timeout occured after 30000ms selecting a server using…
Saad
  • 51
  • 2
3
votes
1 answer

How to make comlex query MongoDB with Powershell

I need to retrieve data from mongoDB using Powershell. Let's say I have db.orders collection and need to retrieve only orders created during last week and retrieve only specific columns for instance _id, status, createdAt fields. Orders collection…
3
votes
2 answers

MongoDb.Driver IMongoDatabase.GetCollectionNamesAsync() Exception

I connect to a MongoDB using the C# MongoDB.Driver library. Some code that works MongoClient client = MongoClientBuilder.Build( "77.199.99.90", 27016, "admin", "pwd"); IReadOnlyList dbNames =…
MoonKnight
  • 23,214
  • 40
  • 145
  • 277
2
votes
1 answer

C# MongoDb - How to update one field in nested documents?

What I want to achieve is to provide List containing client Id and InternalIds of jobs to the Finish() method. Then I want to iterate through clients and update all jobs matches JobInternalIds and set current datetime to FinishedAt…
byasu
  • 33
  • 1
  • 4
2
votes
1 answer

Multiple MongoDb filters in C#

To handle multiple MongoDb filters in C#, I had wrote below method; public string MultipleFilters(string collectionName, Dictionary dictFilters) { var filter = Builders.Filter.Eq("", ""); …
Nands
  • 379
  • 3
  • 19
2
votes
2 answers

How to connect to a server via TLS using MongoDB.Driver with a certificate file?

According to the MongoDB documentation it is supposed to be possible to connect via TLS where you specify the pem certificate by the tlsCAFile parameter. However I have not been able to use the client in such a manner that it is successful.…
Chris Marisic
  • 32,487
  • 24
  • 164
  • 258
2
votes
1 answer

How to join collections by id with MongoDb C# Driver

I'm trying to join two collections by Id. Although I can see rows in the database, the query results are empty. I have two collections: userGames and games Here is my Code to join collections: var userGamesQuery = userGames.AsQueryable() …
AminSojoudi
  • 1,904
  • 2
  • 18
  • 42
1
2 3