Version 2.0 of the C# driver for MongoDB.
Questions tagged [mongodb-csharp-2.0]
187 questions
3
votes
0 answers
IBsonArraySerializer exception when querying using ElemMatch
I have a new query for a collection that is already pulling and storing data for a configured type and I haven't come across that one before:
The serializer for field 'BookingRequests' must implement IBsonArraySerializer and provide item…

Carlos Torrecillas
- 4,965
- 7
- 38
- 69
3
votes
0 answers
Examine query generated from MongoDB projection by C# driver
I'm querying data with C# driver for mongodb using projection. The code is like:
var filter = Builders.Filter.Eq("_id", userId);
var projection = Builders.Projection.Expression(u => Tuple.Create(u.UserId, u.UserName));
var cursor = await…

Jeffrey Zhao
- 4,923
- 4
- 30
- 52
3
votes
1 answer
MongoDB c# driver - How to save class by reference without modifying the object class?
I have 2 classes:
public class Store
{
public Guid ID;
public List Products;
}
public class Product
{
public Guid ID;
public string Name;
}
I want to save "Store" in my MongoDB but I don't want the collection of Stores to…

Aviram Fireberger
- 3,910
- 5
- 50
- 69
3
votes
2 answers
Mongo DB C# Driver 2.0 Synchronous Count
I need to count items that match a filter using an older controller that hasn't been switched to async. We have an async answer on how to do this:
long result = await collection.CountAsync(Builders.Filter.Eq(_ => _.Name, "bar"));
I also…

VSO
- 11,546
- 25
- 99
- 187
3
votes
1 answer
MongoDB C# 2.x Driver ElemMatch with Dictionaries
I am trying to use ElemMatch to find a document in MongoDB using the 2.2 driver with no success. I am receiving an exception such as:
System.InvalidOperationException : The serializer for field
'EnabledForProduct' must implement…

Daniel Polistchuck
- 61
- 5
3
votes
0 answers
Unable to cast object of type 'MongoDB.Bson.BsonString' to type 'MongoDB.Bson.BsonBoolean'
I am getting an error: "Unable to cast object of type 'MongoDB.Bson.BsonString' to type 'MongoDB.Bson.BsonBoolean'."
Here is Code 1:
var json = "{ 'foo': 'bar' }";
var document = BsonSerializer.Deserialize(json);
Here is Code 2 with a…

Shi Her
- 43
- 6
3
votes
1 answer
How do I register a ScalarDiscriminatorConvention for a different field name in MongoDB?
I'm writing C# code to pull data out of an existing MongoDB database and put it into various C# classes. One part of the database is polymorphic: if the field type is A, then a certain set of fields will exist in that document. If type is B, a…

rmunn
- 34,942
- 10
- 74
- 105
3
votes
1 answer
MongoDb c# driver 2.0 Any in many to many
I have the following issue - how to check is there are any element from int array mailListIds contains in MailLists in MailListId field. I think it could be something like the following :
Builders.Filter.AnyIn(p => p.MailLists.Select(m =>…

Vladyslav Furdak
- 1,765
- 2
- 22
- 46
3
votes
1 answer
BSON document to FilterDefinition MongoDb c# driver
How can i convert a BsonDocument to the FilterDefinition instance?
It is a class provided by new MongoDb C# driver.

Vladyslav Furdak
- 1,765
- 2
- 22
- 46
3
votes
1 answer
MongoDB C# driver 2.0: How to get the result from MapReduceAsync
MongoDB C# driver 2.0: How to get the result from MapReduceAsync
I'm using MongoDB version 3, C# driver 2.0 and would get the result of MapReduceAsync method.
I have this collection "users":
{ "_id" : 1, "firstName" : "Rich", "age" : "18" }
{ "_id"…

Leonardo JAS
- 31
- 3
3
votes
3 answers
Project on multiple fields in C# MongoDB 2.0
How do you project on fields in the new MongoDB C# drivers when the fields are given in the form of a String array ?.
I could find ways to project on a single field by doing…

Adarsh
- 99
- 3
- 8
3
votes
0 answers
Grouping mongodb filtered results by reference id throws
I have this simplified model:
public class Parent
{
public ObjectId Id { get; set; }
}
public class Child
{
public ObjectId Id { get; set; }
public ObjectId ParentId { get; set; }
[BsonRepresentation(BsonType.String)]
public…

Ceco
- 1,586
- 3
- 16
- 23
3
votes
2 answers
How to cast mongo collection to interface C#
I have a repository with signature:
public Task> GetList()
{
}
How do I cast mongoDb collection to this interface? (MongoDb Driver 2.0)
public Task> GetList()
{
Task
- > foo =…

Alexander Selishchev
- 1,180
- 13
- 29
3
votes
3 answers
Unable to to query Dictionary item using MongoDB C# 2.0 Drivers
I have a class that has a dictionary property in it.
[DataMember]
[BsonElement("QueriableParameters")]
public Dictionary QueriableParameters
{
get;
set;
}
I'm using the new MongoDB c# 2.0 drivers…

Baku Retsu
- 61
- 5
3
votes
2 answers
MongoServer.State equivalent in the 2.0 driver
In the old API (1.X) you could tell whether the server was connected or not by using the State property on the MongoServer instance returned from MongoClient.GetServer:
public bool IsConnceted
{
get
{
return _client.GetServer().State…

i3arnon
- 113,022
- 33
- 324
- 344