Questions tagged [mongodb-.net-driver]
The official MongoDB .NET Driver provides asynchronous interaction with MongoDB.
2,566
questions
1
vote
0
answers
38
views
'MongoDB.Driver.IFindFluent<XDocument, System.Collections.Generic.List<string>>' to 'System.Collections.Generic.List<string>'
I am working on a asp.net core project with MongoDB.
I want to get a list from Database.
I tried this
public async Task<List<string>> GetRoomCodesFromHotelBooking(string transactionId)
{
...
2
votes
0
answers
961
views
System.FormatException: An error occurred while deserializing the XXX property of class ADocument+BDocument: Unknown discriminator value 'JsonElement'
I am wokring a asp.net core project with mongoDB.
I want to get the list of booked hotels from HotelBookingDocument.
public class HotelBookingDocument
{
public string Id { get; set; }
public ...
1
vote
1
answer
28
views
C# mongodb driver query nested array
I am struggling now since hours to get one query working. My shema looks like the following:
public class ActionResponse
{
public string Id { get; set; }
public List<ActionResponseItem> ...
0
votes
1
answer
97
views
How to use MongoDB Search Index / Indexes on ASP.NET
I have a collection of 10 000 documents, (~ 6 Mb)
When I'm using a simple find to retrieve all the data, it takes like more than a minute to retrieve all the documents.
I created a search Index on ...
1
vote
1
answer
23
views
How to sort dynamically in mongodb
I have a "sort" query parameter. This maybe looking like this:
?sort=-name,+number
Now I want to read this and build a sort query for the c# MongoDB-Driver.
I thought of something like this:...
0
votes
1
answer
64
views
How can I materialize a string to the actual type?
I am creating a projection variable like this:
var projection = Builders<Items>.Projection
.Include(x => x.Name);
The Include method takes an expression ...
0
votes
0
answers
27
views
MongoDB multiple document updation passing multiple parameters
We have a single document updation,
public void Update<T>(string collectionName, T value,string feildName,int id)
{
try
{
mongoServer.Connect();
...
1
vote
2
answers
24
views
Count subdocuments using MongoDB C# driver
I want to count and sum all posts in Items. When i query my collection with:
GetCollection().Find(p => p.Type == "Test") i receive this:
[
{
"Type": "Test&...
0
votes
0
answers
9
views
Mongo Tailable cursor not working when trying to run in separate thread
I am trying to use Mongo Tailable cursor in my application I am using below code to create capped collection and tailable cursor
using MongoDB.Bson;
using MongoDB.Driver;
public static class ...
0
votes
0
answers
22
views
Using extended filters (by field inside field) in MongoDB
There's a list List<BsonDocument> with values like that:
{{ "_id" : 123, "IDD" : 123, "Sc" : { "Field1" : null, "Field2" : "some text|some ...
1
vote
1
answer
43
views
Force MongoDb to use UUID instead of ObjectId
I want to use pure json-data (without de-/serializing in the service) to store in MongoDB and read back and deliver pure json.
The only think I would need is, MongoDB should create "_id" as ...
1
vote
1
answer
40
views
How must a json look to force mongodb to BinData subtype 4
I'm using the c# driver MongoDB.Driver 2.16.0
I'm trying to insert pure json.
I want the _id to be used as the new UUID type aka BinData subtype 4. But I get only subtype 3 or pure string.
var ...
0
votes
0
answers
9
views
mongoimport apply the data type as string for all fields
When we import CSV file data mongodimport automatically choose data type for each field.
Is it possible to apply the data type as the string for all fields? the --columnsHaveTypes can help to define ...
0
votes
1
answer
32
views
Querying a collection via a match in an ID-to-ID collection in MongoDB using C# Driver
I have the following collection document types:
Car
{
Id
Make
Model
}
and
UserCar
{
UserId
CarId (references Car.Id)
}
I'm having trouble finding the correct query using MongoDB C# ...
0
votes
2
answers
35
views
Project single field in array of subdocument returns more than one
I'm having difficulties putting up a code which returns an element in an array of subdocuments. I am actually trying to flatten a document to a new document which is strongly typed. My document is ...
0
votes
0
answers
27
views
Mongodb connection pools with cross region replicas
We have a cluster hosted on Mongo Atlas (M50, AWS) with cross region replicas in 5 other regions. This allows my application servers in those regions to read from a local replica using readPreference=...
0
votes
0
answers
60
views
Read multiple types in a collection using MongoDB C# driver
I try to create a timeline collection that contians multiple types. I have no problem to insert the type or read a specific type. But when i want a list of all types for a specific user, then i got ...
0
votes
1
answer
71
views
C# MongoDB Driver Aggregate() always throw cast exception
I'm trying to join collections with Lookup function:
var docs = await Items
.Aggregate()
.Lookup("categories", "categoryId", "_id", "category")
....
0
votes
1
answer
35
views
How to perform like on MongoDB document for integer values
At the moment, I currently have a "like" statement that works great for strings.
Builders<Book>.Filter.Regex("subject", new BsonRegularExpression(searchString.ToString(), &...
0
votes
0
answers
136
views
Expression of type "System.Collections.Generic.IEnumerable" cannot be used for parameter of type "System.Linq.IQueryable"
I have these two models for MongoDB.Driver:
public class Author
{
[BsonRepresentation(BsonType.ObjectId)]
public string? Id { get; set; }
public string Name { get; set; }
[...
1
vote
2
answers
111
views
Cannot deserialize a 'String' from BsonType 'ObjectId'
I am working a asp .net core project with mongoDb.
I am trying to get hotel by hotelCode.
HotelBedsContentService.cs
public async Task<HotelDocument> GetHotel(int code)
{
var ...
1
vote
1
answer
32
views
MongoDB Driver C# Update a single field in Nested Array of Objects
public class Country
{
public string Id { get; set; }
public string Name { get; set; }
public List<State> States { get; set; }
}
public class State
{
public string Name { get; ...
1
vote
1
answer
46
views
System.NotSupportedException: Member Month of type System.DateTimeOffset in the expression tree {ExampleModel}{EndTime}.Month cannot be translated
I'm trying to do this method:
Task<Result<IQueryable<ExampleViewModel>>> Handle(ExampleQuery request)
{
return Result.Success(_repository.Get()
....
0
votes
1
answer
45
views
C# MongoDb Driver Filter using nested property from collection
I have the following class structures :
public class QuoteRequestInfo
{
. . .
public LocationInfo LocationInfo {get;set;}
. . .
}
LocationInfo has a stop collection which will always ...
0
votes
1
answer
39
views
MongoDB regex filter string array items
Here is document structure
{
"_id" : ObjectId("6284f3eceae4fd4c3cfebb39"),
"Codes" : [
"Code 1",
"Code 2",
"Code ...
0
votes
1
answer
35
views
MongoDB C# Driver Update with Aggregation Pipeline "$replaceOne"
I'm struggling to convert the code below to MongoDB driver C# to an "UpdateMany" with aggregation, can anyone help me?
db.collection.updateMany(
{ URL: { $regex: /helloWorldt/ } },
[{
...
0
votes
1
answer
31
views
Need to update Last record of nested array mongoDB c#
I want to update the last object of nested array. Here is my DB structure.
{
_id:1,
isActive:true,
name:xyz,
student:[
{
id:12,
name:"a",
dateCreated: "1-1-...
2
votes
1
answer
160
views
How to do migration & seed with MongoDB.Driver on Asp.Net Core?
We are building an Asp.Net core web API that must use MongoDb on the backend. According to what I found, it is recommended to use directly MongoDb.Driver because it does already most of the job and it ...
0
votes
0
answers
20
views
Unable to determine the serialization information when create index
I'm having problem when i create a index.
This is my code:
private static IMongoCollection<IPageItem> GetCollection()
{
return Connection.Database.GetCollection<IPageItem>(&...
0
votes
1
answer
164
views
MongoServerError: bad auth
I make an app using node.js. and connect this with MongoDB. But when I start my server it gives me an error. The error is below.
Example app listening on port 5000
MongoServerError: bad auth : ...
0
votes
1
answer
60
views
Casting an object within a MongoDB document to date time within a filter definition builder
I am hoping someone can help me as I am new to Mongo DB or point me to a work around, I have a property within a Mongo DB document which is of type object, but it is a date time, and I would like to ...
0
votes
0
answers
12
views
Mongodb database size 70 gb chunks not performing fetch operation
I am facing issues with mongodb .
there is problem with fetching
data from chunks collection.
taking too much time .
Database size 70 gb . not able to rebuild index.
version 5.0 .
any solution?
0
votes
0
answers
34
views
c# mongodbdriver linq 16mb limitation problem
I query mongodb like this;
List<string> recvDateList = new List<string>();
List<FilterDefinition<VaersData>> filterList = new List<FilterDefinition<VaersData>>();
...
0
votes
0
answers
31
views
Find and Insert function not working inserts only MongoDB C# ObjectID
I have code with my DataBase API, through which I access mongo db.
When I call the Create function, I have a document that only has an ObjectID.
Also, when I call the GetByID function, then my code ...
0
votes
0
answers
24
views
Mongo DB error Nested type initialization C#
I am trying to create a new document in Mongo DB, but I have 2 problems.
My Code:
internal class Doc
{
internal int ItemID { get; set; }
internal string Some { ...
0
votes
0
answers
68
views
Facets and lookup in Mongodb C#
I have 2 facet on User collection, which are concatenated to create a new array. For each document, i have reference ids to address collection. I need to get the detail about the address. Can it be ...
0
votes
0
answers
31
views
MongoDB Pull Without a Filter Parameter
I have write this code;
var pl = Builders<CMainList>.Update.PullFilter(x => x.SList,
Builders<CMain>.Filter.Eq(y => y.TID, tid) &
Builders<CMain>.Filter.ElemMatch(y ...
0
votes
1
answer
45
views
get additional data on same collection in Mongodb C#
I have a collection called "User". I'm passing userid to get the record. In addition to that i also need additional 10 last updatedAt(DateTime) record excluding the userid record but added ...
1
vote
2
answers
77
views
Is there a way to use `ClassMap` to map one document property to multiple class properties?
Let's say I have a mongo document that looks like this:
{
"name": "John Doe"
}
Now let's say my model looks like this:
public class Person
{
public string FirstName { get; ...
0
votes
1
answer
40
views
How can I flatten this array of subdocuments?
This is the query I want to execute in my C# code:
db.Courses.aggregate([
{$unwind: "$topics"},
{$project: {"topics":1, _id:0}},
{$replaceRoot:{newRoot:"$topics"}}
]...
1
vote
0
answers
29
views
.Net MongDB Driver more than 5x slower than pymongo equivalent
I have a collection with ~8.5k documents.
This Python code gets the last added document in ~50-70ms:
from pymongo import MongoClient
import pymongo, time
client = MongoClient(connectionString)
db = ...
0
votes
1
answer
65
views
Cannot run commands like "shardCollection" or "enableSharding"
I inherited a project to maintain. Apparently there was a decision to switch from CosmosDb to dedicated MongoDb. There is a project in a CI pipeline that seeds mongo database with collections and ...
0
votes
1
answer
96
views
How to find a document with Bson type in mongo in c#
I want to find a role details with specified username in MongoDb with Drivers in C#.
I don't want to use any builders or linq methods.
I tried this to insert a Bson document and it worked.
...
0
votes
2
answers
89
views
MongoDB C# Driver: Nested Lookups - How do I "join" nested relations?
I have 3 MongoDB collections that are related to each other:
Company
Store: a Company can have multiple Stores
Product: a Store can have multiple Products
Company
{
"_id": { "$oid&...
0
votes
1
answer
72
views
Performance penalty when using fluent interface
I am an absolute beginner when it comes to MongoDb. Just joined a new project where it is used, so I tried to do few experiments to get myself familiar. I got to an issue and I cannot find a ...
0
votes
1
answer
30
views
MongoDB - How to push an embedded array into an existing document
Model:
[BsonIgnoreExtraElements]
public class UserPortfolioList
{
public string? Username { get; set; }
public List<Pflist>? Pflist { get; set; }
}
public class Pflist
{
public ...
0
votes
0
answers
102
views
C# MongoDB Driver Update with Linq, Query in array->array->array with multiple conditions
var collection = MongoDB.GetCollection<farray>(MAINDB);
var pl = Builders<farray>.Update.Push("f1.$.f2.$.f3.$.f4", new Puts() { ID = new STX() {ID=...
1
vote
2
answers
336
views
C# MongoDb Driver Convert string to DateTime and for Filter Builder
var builder = Builders<ModelClass>.Filter;
var filter = builder.Where(x => x.Active);
if (fromDate.HasValue)
{
var date = fromDate.Value;
var subfilter = ...
0
votes
1
answer
66
views
Mongodb c#driver - AggregateToCollectionOperation
I'm using the library MongoDB.Driver 2.8.1 (i'm planning to upgrade to the latest version, it's an old project).
I'm trying to use the operator $out for a query in my code so I wrote this piece of ...
0
votes
1
answer
45
views
Compare tow fields of a list with data in mongoDb c# driver
Let's say I have an in-memory list called filterProfile.
var filterProfile = people.Select(x => new {x.Name,x.Age}).ToList();
I need to run a query like this in mongodb:
var resultData = await ...