Questions tagged [mongodb-csharp-2.0]

Version 2.0 of the C# driver for MongoDB.

187 questions
1
vote
2 answers

How can I complete a string concatenation inside a project stage using C# and the Mongo aggregation pipeline?

I'm trying to perform a string concatenation within a project stage of a MongoDb aggregation pipeline operation. I need to add a field called "coid" to a document, which is to be the result of a string concation between 2 strings: the string…
1
vote
0 answers

MongoDB C# Driver Projection and Serialization

I have got a working code to join two mongo collections using $lookup. [HttpGet("mongojoin")] public IActionResult GetMongoJoinCollection([FromQuery(Name = "schoolId")] Guid schoolId) { var tabAssessmentCollection…
Ajeesh Joshy
  • 1,387
  • 2
  • 18
  • 32
1
vote
1 answer

How to use formula (or Expression) to update value using Mongo DB C# Drivers 4.2?

I am quite new to MongoDb (and MongoDb C# Drivers) and lately, we are trying to implement an update wherein we use the value of a field and a variable (method parameter) to update several fields. Basically, our doc is something like this public…
Charles -
  • 13
  • 3
1
vote
1 answer

Update document with its value

Need to update a document based its value var filter = Builders.Filter.Empty; var update = Builders.Update.Set(i => i.JobDuration,…
1
vote
2 answers

Distinct count with group fails though count is working fine

I'm trying to convert a sql server query to Mongo C# driver LINQ. I have a table with multiple entries for each guid and each entry has different code value. I need get a distinct count of guids for each code. I'm able to do Count()in LINQ but when…
1
vote
2 answers

Projection after Group

I'm trying to make a Projection right after a Group clause in my C# application but I'm getting "doesn't contain definition for 'Project' " error. Mongo DB - Code that has worked: var pipeline = [ { $match:{ externalId:…
Glenn Mateus
  • 319
  • 1
  • 2
  • 17
1
vote
1 answer

C# Mongo DB driver - expression with method call not working

I'm trying to query some data and projecting to a class with fewer properties by sending an expression (C# mongo driver version 2.7.3). I am trying to understand why a specific expression fails. The failure greatly limits the user from writing a…
Metheny
  • 1,112
  • 1
  • 11
  • 23
1
vote
0 answers

Mongodb c# ElemMatch not working on array

i am trying to fetch element based on a property of a sub collection. var filter = Builders.Filter.ElemMatch(x => x.BusinessRequestStatuses, x => x.RequestId == requestId); var res = await…
Raas Masood
  • 1,475
  • 3
  • 23
  • 61
1
vote
0 answers

Filtering in mongo by interface

I have a mongo collection that I want to type to an interface. It should be able to contain multiple concrete types, all of which implement this interface. However when making queries if I use the interface it tells me that it cannot find…
Chris
  • 27,210
  • 6
  • 71
  • 92
1
vote
1 answer

How do I skip duplicate documents in a bulk insert and ignore duplicates with a specific field c#

I need to insert many documents and ignore the duplicated docs. Doc format: _id:5b84e2588aceda018a974450 Name:"Jeff M" Email:"jeff.m@xtrastaff.com" Type:"Client" UserId:Binary('Rw+KMGpSAECQ3gwCtfoKUg==') UserImage:null I want to check the…
1
vote
1 answer

Find Distinct Count in MongoDB using C# (mongocsharpdriver)

I have a MongoDB collection, and I need to find the distinct count of records after running a filter. This is what I have right now, var filter = Builders.Filter.Eq("bar", "1"); db.GetCollection("FooTable").Distinct("zoo",…
coder_andy
  • 376
  • 1
  • 3
  • 17
1
vote
1 answer

MongoDB selecting key value pairs using C# driver

I have a MongoDB collection that looks similar to this: { _id : 1, key : "key1", value : [ "val11", "val12"] } { _id : 2, key : "key2", value : [ "val21", "val22", "val23"] } I'd like to get a List of MyObjects ( MyObject consisting of…
Darkersan
  • 21
  • 2
1
vote
1 answer

Password Special Charecter issue in mongoDB?

Error : Password Special Character issue in mongoDB Code: connstr="mongodb://test:test@123@67.186.193.192:27017/testdb" Here i changed password "test@123" to "test%4123" . Because @ ASCII code is %4 Now it is working fine. MongoClient client = new…
user8221107
1
vote
2 answers

How to replace only not sent null fields in mongodb

How to replace only not sent null fields. My Product Instance: Product p1 = new Product(){ Name : "Apple", Money: 2 }; My Document: { "Id" : 1 "Name" : "Apppple", "Money" : 3, "Color" : "Red" } I runned this code: var _filterDef =…
Biletbak.com
  • 409
  • 5
  • 14
1
vote
1 answer

How To Set Properties Dynamically In The MongoDB C# Driver

I have created an extension method that accepts a JObject and generates an update definition for the C# MongoDB Driver. The idea is that the properties and values in the JObject are used to map to and update properties in the database. However, the…