Version 2.0 of the C# driver for MongoDB.
Questions tagged [mongodb-csharp-2.0]
187 questions
2
votes
0 answers
MognoDb c# driver 2.0 serialize query
I have a defenition of generic FilterDefenition - FilterDefinition matchfilter. How can i convert it into MongoDb query ? When i try to get JSON i recieve
"{ \"_t\" : \"AndFilterDefinition``1\" }"
how to get a real query ?

Vladyslav Furdak
- 1,765
- 2
- 22
- 46
2
votes
1 answer
MongoDb c# driver 2.0 query styles
Early we used a LINQ provider for MongoDb, but now we have migrated to MongoDb c# driver 2.0 and there are a few things that i don't understand.
When we used a LINQ provider the query was like the following:
var query = from c in…

Vladyslav Furdak
- 1,765
- 2
- 22
- 46
2
votes
1 answer
MongoDb c# 2.0 driver AddToSet method
I have the following code which was implemeted with MongoDb 2.0 c# driver. But I need to access to the MailLists collection of Profile which will be inserted. I've written the expected solution using p in constructor, but how to implement it via…

Vladyslav Furdak
- 1,765
- 2
- 22
- 46
2
votes
1 answer
How to use C# Mongodb driver typed methods Update fields of array document elements
Using the MongoDB C# Driver version 2.0.1 with Mongodb 3.0, is it possible to use typed methods to update an array field document element?
For example, I have the following document:
{
Name:"Ken",
ContactNo:[ { Number:"123",…

kenalex
- 61
- 1
- 10
2
votes
1 answer
MongoDb c# Driver typed Builder with string args
How can I implement a typed Builder using string fieldname and value, like in the following code:
Builders.Filter.Eq(fieldName, value)
I can implement it with BsonDocument data type, but I need to retrieve a typed Profile FilterDifinition.

Vladyslav Furdak
- 1,765
- 2
- 22
- 46
2
votes
0 answers
MongoDb c# Driver bulk update with pull
I have the following code which was written via old legacy c# mongodb driver :
var bulk = dbCollection.InitializeUnorderedBulkOperation();
foreach (var profile in profiles)
{
bulk.Find(Query.EQ("_id",…

Vladyslav Furdak
- 1,765
- 2
- 22
- 46
2
votes
2 answers
Add element or add to array using MongoDB C# driver 2.0
I have a document that can have a "Favorites" element on it and I'm trying to push a new value into an array on that element. However, I'm getting an error because the document I'm trying to update doesn't have the "Favorites" element. How can I…

adam0101
- 29,096
- 21
- 96
- 174
2
votes
1 answer
Upgrading IBsonSerializer with Mongo driver 2
The old implementation of the Mongo Drivers was leading to this kind of code:
public object Deserialize(BsonReader bsonReader, Type nominalType, Type actualType)
{
if (nominalType == typeof(T))
{
if (typeof(V) == typeof(string))
…

Revious
- 7,816
- 31
- 98
- 147
2
votes
2 answers
MongoDb Create Repository Pattern with new Async methods
public class MongoDbRepository : IRepository where T : IEntityBase
{
private IMongoDatabase database;
private IMongoCollection collection;
public MongoDbRepository()
{
GetDatabase();
GetCollection();
}
…

Ivaylo Zhelev
- 47
- 2
- 5
2
votes
1 answer
MongoDB .Net driver 2.0 Builders Filter (field to array comparison)
I need to get all usernames from "followingList.username" and compare with
posts' usernames, if there any match need to add that one to an array.
Person Model
{
"_id" : ObjectId("554f20f5c90d3c7ed42303e1"),
"username" : "fatihyildizhan",
…

fatihyildizhan
- 8,614
- 7
- 64
- 88
1
vote
1 answer
Get summation of all field in mongodb c#
I have a mongodb which looks like this
[
{
"client_id": "abc",
"product_id": "123",
"weight": {
"value": 100
"unit": "kg"
}
},
{
"client_id": "def",
"product_id": "456",
"weight": {
"value": 200
…

mohamed elsabagh
- 352
- 3
- 16
1
vote
0 answers
MongoDB slow fetching using MongoDB C# driver 2.13
I'm trying to fetch 40000-50000 documents from the MongoDB collection using the MongoDB c# driver.
It's taking more than 1 min to fetch documents(40000 docs) using the find().toList() method
But we have a requirement to fetch all documents from the…

Nikhil Shinde
- 11
- 1
1
vote
1 answer
MongoDB .Net Driver - Filter Builder throwing an exception
I am trying to fetch a Document from MongoDB using the C# MongoDB driver.
public class Record
{
[BsonId]
public ObjectId Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public Data {…

Chand
- 51
- 7
1
vote
1 answer
InsertManyAsync vs BulkWriteAsync: in one transaction or not, max rows allowed via MongoDB C# driver
I have questions on InsertManyAsync vs BulkWriteAsync via the NuGet below:
https://www.nuget.org/packages/MongoDB.Driver/2.12.3?_src=template
I want to export 300,000 rows of data around 20 MB, convert them into JSON and import them into Mongo…

Pingpong
- 7,681
- 21
- 83
- 209
1
vote
0 answers
MongoDB C# driver: Setting consecutive item number during insert
Using mongodbdriver in version 2.10 in a C# project.
I have a document type as follows:
{
"_id" : ObjectId("609720e0fc341e5879c91779"),
"number" : "1"
}
Currently when creating a new object, I set the number manually:
var item = new…

Thor
- 31
- 2