mongodb-.net-driver

Update List<string> in mongoDB

房东的猫 提交于 2019-12-24 19:43:03
问题 I have a list of strings I want to update in MongoDB using C# driver. How do I do this? List<string> Images = someList; var update = Update.Set("Images", Images); collection.Update(query, update, UpdateFlags.Upsert); this will give me an error saying that 'Images' is not BsonValue.. How do I convert string list to the bsonvalue? Thanks 回答1: It looks like Update.Set is wanting a BsonValue and you can't implicitly convert from List to BsonValue. You look like you are doing Upserts anyway, could

LinqToMongo Inject

百般思念 提交于 2019-12-24 18:51:56
问题 I have a .NET app which uses MongoDB so I am using the Mongo C# driver. The driver version I am currently using is 1.9.2 and everything in my app works as expected. However I am trying to upgrade the Mongo driver to latest version 2.7.0 however I am having some issues getting some things working. The below Code snippet is where I am facing an issue with latest version of driver public IQueryable<Location> SearchByLocationDistance(double latitude, double longitude, double rangeInKm) { var

The wait queue for acquiring a connection to server ******* is full. [MongoDB]

一笑奈何 提交于 2019-12-24 17:49:56
问题 I'm having this error... I'm using ASP.NET Core with the last version of driver C#. The wait queue for acquiring a connection to server [server:port] is full. Failed Method: MongoDB.Driver.Core.ConnectionPools.ExclusiveConnectionPool+AcquireConnectionHelper.CheckingOutConnection Call Stack: MongoDB.Driver.MongoWaitQueueFullException MongoDB.Driver.Core.ConnectionPools.ExclusiveConnectionPool+AcquireConnectionHelper.CheckingOutConnection MongoDB.Driver.Core.ConnectionPools

How to get a document in mongoDb via a nested property through .net mongoDb driver

旧巷老猫 提交于 2019-12-24 17:06:52
问题 Suppose i have following document in some collection [{ "name": "Man1", "Childrens": [ { "name": "Children 1", "age": "12" }, { "name": "Children 2", "age": "18" }, ] }, { "name": "Man1", "Childrens": [ { "name": "Children 3", "age": "12" }, { "name": "Children 4", "age": "18" }, ] } ] i want to get the document where name of one of the children is "Children 1" I want to achieve this via .net mongo driver var bQuery = String.Format("{{ '{0}':'{1}' }}","Childrens.name","Children 1"); var

How to resolve null data on Observable Collection to data grid binding?

眉间皱痕 提交于 2019-12-24 15:02:15
问题 I've set up a database on MongoLab that is queried and parsed to a Model. The collection in that model is in turn bound to the data grid. But when I query the database, the only data showing on the grid is the object ID for the document. In order to debug the issue I initialized the list with constant data for each field, and the binding works, filling each field on the grid. Which then lead me to check how I'm mapping the data to the Model. I then stepped through the contents of the

C# MongoDB - How to add and remove item to multiple nested array elements?

我的未来我决定 提交于 2019-12-24 12:06:19
问题 I have a document in MongoDB that looks like that: { "Id":"123", "Product": "test", "Tags":[ { "Name": "name", "Categories": [ { //item }, { //item } ] }, { "Name": "name", "Categories": [ { //item }, { //item } ] } ] } Now, I need to add a new Item and it needs to be added to all of the categories of the Tags element of that Product by its Id . For example, when I'll insert Item 3 the document should look like this: { "Id":"123", "Product": "test", "Tags":[ { "Name": "name", "Categories": [

How do you filter updates to specific fields from ChangeStream in MongoDB

為{幸葍}努か 提交于 2019-12-24 09:54:19
问题 I am setting up a ChangeStream to notify me when a document has changed in a collection so that I can upsert the "LastModified" element for that document to the time of the event. Since this update will cause a new event to occur on the ChangeStream, I need to filter out these updates to prevent an infinite loop (updating the LastModified element because the LastModified element was just updated...). I have the following code that is working when I specify the exact field: ChangeStreamOptions

Run MongoDump / MongoRestore in C#

萝らか妹 提交于 2019-12-24 09:02:28
问题 Is there an easy way to run these commands using the C# driver? The only documentation I found involves running the EXE as a process etc, which seems a bit heavy. The only related question I found was unanswered... am I missing something fundamental here? http://grokbase.com/t/gg/mongodb-user/127zntq9pr/mongodump-in-c 回答1: mongodump and mongorestore are applications, not MongoDB commands which is why you would have to run the executable. If interested, the C++ code for dumping a database is

Update field inside the list using MongoDB C# driver

血红的双手。 提交于 2019-12-24 05:44:30
问题 I have multiple MongoDB documents like this: { "_id":"abcde", "Students":[ {"Name":"John","IsNew":true}, {"Name":"Steve","IsNew":true} ], } { "_id":"fghij", "Students":[ {"Name":"Ron","IsNew":true}, {"Name":"Mike","IsNew":true} ], } How to update the IsNew field to false for all students for every document using C# driver? 回答1: You can use UpdateMany method from MongoDB C# driver with the positional all operator: var filter = Builders<YourModel>.Filter.Exists(x => x.Students); FieldDefinition

The SQL query text exceeded the maximum limit of 30720 characters in Azure CosmosDB

只谈情不闲聊 提交于 2019-12-24 01:20:06
问题 I have a query where I use an array with an "IN" style setup. var builder = Builders<Transaction>.Filter; var filter = builder.Eq("App", app) & builder.In("TransactionId", incomingIds); List<string> existingTransactions = collection .Find(filter) .Project(x => x.TransactionId) .ToList(); A while back this started to throw the error below and I had reduce my batch-size significantly to avoid the error. Command delete failed: Errors encountered exception while executing function. Error while