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
25
votes
4 answers

MongoDB .Net driver 2.0 Pull (remove element)

Can you help me to run correctly "Pull (remove)" with 2.0 driver. I have a collection like this and I want to remove first follower named as fethiye by follower field. { "_id": ObjectId("554e05dfc90d3d4dfcaa2aea"), "username": "bodrum", …
fatihyildizhan
  • 8,614
  • 7
  • 64
  • 88
25
votes
2 answers

MongoDB best practice for referencing

I'm wondering what the best practice for modelling by using references would be given situation under. I'm using MongoRepository library. public class User : Entity { publis string Id { get; set; } public string Email { get; set; } public…
Xatep
  • 353
  • 1
  • 5
  • 11
24
votes
2 answers

Adding BSON array to BsonDocument in MongoDB

How can I add BsonArray to BsonDocument in MongoDB using a C# driver? I want a result something like this { author: 'joe', title : 'Yet another blog post', text : 'Here is the text...', tags : [ 'example', 'joe' ], comments : […
Ravi
  • 2,470
  • 3
  • 26
  • 32
24
votes
1 answer

Aggregate $lookup with C#

I have the following MongoDb query working: db.Entity.aggregate( [ { "$match":{"Id": "12345"} }, { "$lookup": { "from": "OtherCollection", "localField":…
TomSelleck
  • 6,706
  • 22
  • 82
  • 151
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
22
votes
7 answers

MongoDB how to check for existence

I would like to know how can I check the existence of an object with mongoDB and C#. I've found a way to do it but I had to use Linq thanks to Any() method, but I'd like to know if it's possible to do it without Linq…
John
  • 4,351
  • 9
  • 41
  • 57
22
votes
2 answers

Collection ID length in MongoDB

i am new to mongodb and stack overflow. I want to know why on mongodb collection ID is of 24 hex characters? what is importance of that?
ashish bandiwar
  • 378
  • 1
  • 3
  • 12
21
votes
5 answers

ReplaceOne throws duplicate key exception

My app receives data from a remote server and calls ReplaceOne to either insert new or replace existing document with a given key with Upsert = true. (the key is made anonymous with *) The code only runs in a single thread. However, occasionally,…
Kun Ren
  • 4,715
  • 3
  • 35
  • 50
21
votes
1 answer

MongoWaitQueueFullException: The wait queue for acquiring a connection to server is full

Sometimes when inserting a small bunch of different document (synchronously), I get the following exception (see full stack trace further down): MongoDB.Driver.MongoWaitQueueFullException: The wait queue for acquiring a connection to server…
Dave New
  • 38,496
  • 59
  • 215
  • 394
20
votes
6 answers

How to make nested queries in MongoDb that works like nested Sql select queries

I want to make an efficient query in MongoDb to find all users who have their userids listed in a usergroup. Ideally I want to make this as a single request to Mongodb. What I want corresponds to nested selects in SQL. I have tried this in the mongo…
ssn
  • 2,337
  • 4
  • 21
  • 27
20
votes
2 answers

How can I update mongodb document for adding a new item to array?

I couldn't figure out insert to a sub array... _id MyArray --Item ----ArrayItemId ----Name I want to insert items to MyArray... How my update document should be? MyCollection.Update( new QueryDocument { { "_id", MyObject.Id } }, new…
Serdar
  • 1,416
  • 2
  • 17
  • 43
20
votes
4 answers

Mongo Schema-less Collections & C#

I'm exploring Mongo as an alternative to relational databases but I'm running into a problem with the concept of schemaless collections. In theory it sounds great, but as soon as you tie a model to a collection, the model becomes your defacto…
Timothy Strimple
  • 22,920
  • 6
  • 69
  • 76
20
votes
4 answers

Filter only by Date using MongoDB C# driver

I am using MongoDB C# latest driver i.e 3.+ in my project. I have different date filter criteria like Today, Last Day, Yesterday, This Month etc by using daterangepicker. Here is my model: public class Student { public Student() { } [BsonId] …
Ghazanfar Khan
  • 3,648
  • 8
  • 44
  • 89
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