Version 2.0 of the C# driver for MongoDB.
Questions tagged [mongodb-csharp-2.0]
187 questions
4
votes
1 answer
MongoDB join using Linq
CommentCollection
{
"_id":"5b63f0f23846b70011330889",
"CommentType":"task",
"EntityReferenceId":"6082ef25-6f9a-4874-a832-f72e0f693409",
"CommentLink":null,
"EntityName":"task2",
"participants":[
…

Ajas Aju
- 725
- 7
- 30
4
votes
1 answer
MongoDB c# Driver: How to set SetIgnoreIfDefault for all members in a class
I would like to SetIgnoreIfDefault(true) for ALL properties of a class. (this can save TONS of default data in the storage)
I can call SetIgnoreIfDefault explicitly for every property:
BsonClassMap.RegisterClassMap(cm =>
{
…

Aviko
- 1,139
- 12
- 21
4
votes
1 answer
Read Specific field values from MongodbC#
Recently I started using MongoDB.I have to read specific fields(columns) from mongodb using mongodb C# driver.That means i have to read specific fields no matter whatever the values.i need to just specify the fields.I have unstructured data in my…

Ajas Aju
- 725
- 7
- 30
4
votes
1 answer
Web api 2 and Mongodb v2 Migrate sample code to using driver version 2
I am trying to convert the project from here https://github.com/attilah/AngularJSAuthentication to using the mongo driver version 2 the latest one so I can adapt to my current project.
I nearly completed of my migration but I face with a few files…

tree em
- 20,379
- 30
- 92
- 130
4
votes
2 answers
Querying, filtering and updating multiple level nested arrays in MongoDB using C#
I have this MongoDB document. I am developing an MVC application and trying to update the comment array (commented description to "comment after update") using C#. I'm using the new mongodb version.
{
"ProjectID":1,
"ProjectName":"Project…

Cisco
- 41
- 1
- 3
4
votes
3 answers
Serializing C# classes to MongoDB without using discriminators in subdocuments
I'm writing C# code that writes to a Mongo database used by an existing Web app (written in PHP), so I need to not change the existing structure of the database. The database structure looks something like this:
{
"_id":…

rmunn
- 34,942
- 10
- 74
- 105
4
votes
1 answer
'MongoDB.Bson.BsonElement' is not an attribute class on simple POCO
This is my POCO:
private class Widget
{
public int Id { get; set; }
[BsonElement("x")]
public int X { get; set; }
public override string ToString()
{
return "Id: " + Id + " X: " + X;
}
}
And I get an error on the…

SNag
- 17,681
- 10
- 54
- 69
4
votes
2 answers
Using C# MongoDB v2 driver with discriminator and polymorphism
Using C# MongoDB LINQ with discriminator describes exacty what I am trying to do, but I am trying to use the new official 2.0.1 driver.
I have a series of subclasses with their specialised properties all inheriting from a base class containing…

Bob Gear
- 174
- 1
- 3
- 13
4
votes
1 answer
MongoDb c# driver 2.0 BsonNull usage
I have isDeleted Nullable property in Profile class.
Builders.Filter.Eq(p => p.IsDeleted, BsonNull.Value)
But the following code raised next compilation error:
Error 11 Cannot convert lambda expression to type…

Vladyslav Furdak
- 1,765
- 2
- 22
- 46
4
votes
1 answer
MongoDb bulk operation get id
I want to perform bulk operation via MongoDb. How to get array of Ids that will be returned after it?
Can i perform single-operation insert faster without using bulk ? Can you advise me some other approach ?
I'm using C# mongoDb driver 2.0 and…

Vladyslav Furdak
- 1,765
- 2
- 22
- 46
4
votes
1 answer
mongodb c# select specific field
Need some help creating a generic method for selecting fields by their name.
something like this:
T GetDocField(string doc_Id, string fieldName)
The best I got is using projection which gives me the doc with only the wanted field seted:
public…
user4781762
4
votes
1 answer
How to use MongoDB C# Driver without specifying a class
I am using MongoDB c# driver 2.0. I a trying to get a collection without specifying a type or class. Observe:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using…

Luke101
- 63,072
- 85
- 231
- 359
3
votes
2 answers
MongoDB class has argument but none are configured
I have a class with some read only properties that I want to store using mongodb.
User.cs
public class User: ValueObject
{
public UserId Id { get; }
public string Firstname { get; }
public string Lastname { get; }
…

G. Houssem
- 33
- 1
- 4
3
votes
2 answers
MongoDb C# Typed Aggregations with Group Unwind and Project
I have a collection like this:
[{
"_id": 1,
"OtherProperties": 100
"PersonInventory": [{
"FirstName": "Joe",
"MiddleName": "Bob",
"LastName": "Blogs",
"PersonId": 1
}]
},{
"_id": 2,
"OtherProperties": 1005
…

gdp
- 8,032
- 10
- 42
- 63
3
votes
0 answers
Mongo DB C# driver - how to define composite ID without attributes?
I need to define a composite key (_id) on an existing class (MyClass), which is composed of 2 class properties: Id & Version.
Also, it has to be done via the BsonClassMap API (and not property attributes), since I cannot change the class code.
I…

Metheny
- 1,112
- 1
- 11
- 23