Version 2.0 of the C# driver for MongoDB.
Questions tagged [mongodb-csharp-2.0]
187 questions
2
votes
1 answer
Flatten [BsonExtraElements] to key value pair json output
I am using [BsonExtraElements] in c# to capture additional data that cannot be mapped to my class.
public class QuestionAnswerClass
{
public string Name { get;set;}
[BsonExtraElements]
public Dictionary AdditionalData…

user9947392
- 33
- 2
2
votes
0 answers
Mongo C# bulk upserts performance issues
Currently I am working on CSV imports with mongo and c#.
var contractModels = listContracts.Select(item =>
new ReplaceOneModel(
new…

SutharMonil
- 78
- 3
- 19
2
votes
1 answer
Cannot get group items from group in GroupBy on IMongoQueryable mongodb c# driver linq statement
When I try this:
var groupedItems = _collection
.AsQueryable()
.GroupBy(pv => pv.ArticleNumber, (k, s) => new { k, Items = s })
.Select(group => group.Items)
.ToList();
I get the following exception:
System.ArgumentException:…

sprengo
- 138
- 9
2
votes
1 answer
Get MongoDb results and count of aggregation using C# driver
I'm using Aggregation to do a query and lookup. What's the most efficient way of returning both the results and count using one server call?
I've seen there is a way to do this using Facets, however, I'd like to do this using a Fluent expression…

Graeme
- 773
- 1
- 8
- 18
2
votes
1 answer
Serialize mongodb document to domain object
I'm trying to read a mondodb document into my domain class (Company) but get an error on one of the properties.
The error message reads:
"Expected a nested document representing the serialized form of a
OrgNumber value, but found a value of type…

Øystein
- 1,163
- 1
- 12
- 23
2
votes
1 answer
how to update mongo db all records in c#
I have mongo db collection which stores the JSON.
By mistakenly, one element value was updated wrong in all records of a collection.
How i will update the particular element ?
My json is like
{
status:
{
name:"john",
value:…

Ponmani Chinnaswamy
- 705
- 7
- 21
2
votes
0 answers
MongoDB self join(aggregation) of collection with parent references
Hello I have this collection, with parent references, I need to do self join on this collection, so that output will contain the children to maximum depth in one document and also get the output based on "Type" field.
{
"DescId" : "1",
…

Vani Kulkarni
- 93
- 12
2
votes
1 answer
Aggregate C# groupby in array
I have the following structure and I want to aggregate over a list of movies to get all the actors and their image.
{
"_id" : 1,
"Title" : "Pirates of the Caribbean: The Curse of the Black Pearl",
"Actors" : [
{
"Name" : "Johnny Depp",
…

Colin
- 759
- 1
- 5
- 20
2
votes
1 answer
C# Driver- LINQ - Aggragate - Contains in Int[]
Mongo Driver Version: 2.2.4.26
I have the following query that performs some aggregations. If I remove the Contains predicate from my Where clause, the query executes successfully.
I would like to reduce and perform the aggregation on the server…

Lui_B
- 81
- 1
- 1
- 5
2
votes
1 answer
Linq to MongoDB Filter
I have a MongoDB collection, listed below:
{
"_id" : ObjectId("001"),
"ticker" : "MSFT=US",
"exchange" : "OTC",
"localtick" : "MSFT",
"compname" : "Microsoft",
"currency" : "USD",
"insertedtime" :…

inquisitive_one
- 1,465
- 7
- 32
- 56
2
votes
0 answers
c# mongo 2.0 move from one array to another
I have a document with 2 arrays.
I want to pull something from the first array and add it to the other.
Only way I know is completely FindOneAndUpdateAsync, get the instance and add it to set.
problem is, this is not atomic.
I would love to get a…

Ori Refael
- 2,888
- 3
- 37
- 68
2
votes
2 answers
How to upsert a document in MongoDB .Net?
I'm adding an UpdateCustomer method that passes in the modified customer to be persisted to the DB. But I've come across an error when calling ReplaceOneAsync on the updated document.
I've consulted the following example and api reference, which…

Brian Var
- 6,029
- 25
- 114
- 212
2
votes
1 answer
How do you set the readPreference for a single query against mongo using the c# driver
I have an application using a number of different mongo databases and 99% of the time it needs to read from the primary of the replica set but I have a couple reporting queries that pull back a lot of data and are not covered by indexes and I would…

runxc1 Bret Ferrier
- 8,096
- 14
- 61
- 100
2
votes
1 answer
MongoDb C# Driver 2.0 add item to nested array
I have a Profiles document collection with array of the following documents :
public class Profile2MailList
{
[BsonElement(elementName: "listId")]
[BsonRequired]
public int MailListId;
[BsonElement(elementName: "status")]
…

Vladyslav Furdak
- 1,765
- 2
- 22
- 46
2
votes
1 answer
MongoDB .NET driver find all : How to write it better?
I am able to query all the items of a collection using 2 approaches
a)
var findAll = await Context.ItemsCollection.FindAsync(_ => true);
var res = await findAll.ToListAsync();
b)
var res = await.Context.ItemsCollection.Find(_ =>…

g bas
- 798
- 1
- 5
- 18