mongodb-.net-driver

how do add multi sql dependency to this code?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-11 12:57:27
问题 i have person table in sql server with fields id and Name and csharp statement that work well. using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace SQLNotifications { public partial class Form1 : Form { public Form1() { InitializeComponent(); } string connectionstring = @"Server=EEPERSIAN-PC\SQLEXPRESS;Database=Chatter;User ID=sa;pwd=1";

MongoDB c# retrieve all the matching elements in an array within a document using Definition builder

人走茶凉 提交于 2019-12-11 12:44:27
问题 I have a document that looks like this in structure with nested sub document { "_id":ObjectId("50419077c2e6a1e18a489a0f"), "user":"Jone Doe", "fooArray":[ { "plot":"circle", "color":"yellow", }, { "plot":"circle", "color":"red", }, { "plot":"square", "color":"green", } ] } And I want to retrieve all the matching elements in fooArray in this document that has circular plot. This is what I tried var filter = FilterBuilder.filter.Eq(doc => doc.User, User); var projection = ProjectionBuilder

FluentMongo throwing error all of a sudden

ぃ、小莉子 提交于 2019-12-11 12:27:28
问题 I am using FluentMongo and the MongoDBCSharpDriver. My code was working fine for a while, but after updating my MongoCSharpDriver, I now I keep getting this error when I try to query the database: "Discriminators can only be registered for classes, not for interface MyLib.Services.IRepoData." The interface IRepoData is just one that I use for all my objects saved to MongoDB. It just defines _id for everything. Here is the line that is breaking: var item = Collection.AsQueryable()

: MongoDB.Driver.MongoConnectionException: An exception occurred while opening a connection to the server

耗尽温柔 提交于 2019-12-11 10:57:14
问题 So, I am using MongoDB on a Azure VM and I have a web site hosted on Azure web Sites as a service. My problem is: Sometimes I get an error like this: "Exception: MongoDB.Driver.MongoConnectionException: An exception occurred while opening a connection to the server. ---> System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond" After

Unable to use BsonIgnoreIfDefault for property of type long

巧了我就是萌 提交于 2019-12-11 09:31:38
问题 [BsonDefaultValue(0)] [BsonIgnoreIfDefault] public long TotalItems { get; set; } The attribute [BsonDefaultValue(0)] is preventing the complete document being inserted into the mongo whereas I just want to prevent storing TotalItems if its value is zero. If I don't use the attributes [BsonDefaultValue(0)], [BsonIgnoreIfDefault] the the document is inserted properly in the db with TotalItems is inserted in the document as "TotalItems" : NumberLong(0)" which I actually don't want to strore into

Encoding issue with string stored in database

别来无恙 提交于 2019-12-11 08:28:00
问题 I have an encoding problem. I have text in my MongoDB that is wrongly encoded. The source file of the texts in my db is encoded in ISO-8859-1. Now, in viewing it in my db, some characters were broken (become '�'). Currently, in retrieving text from db i tried the following codes. var t = Collection.FindOne(Query.EQ("id", "2014121500892")); string message = t["b203"].AsString; Console.WriteLine(ChangeEncoding(message)); First attempt: static string ChangeEncoding(string message) { System.Text

Comparing two fields of mongo collection using c# driver in mono

一笑奈何 提交于 2019-12-11 07:59:58
问题 Am completely new to Mongodb and C# driver. Development is being done using Monodevelop on Ubuntu 14.04 and Mongodb's version is 3.2.10 : Currently my code has a POCO as below: public class User { public String Name { get; set;} public DateTime LastModifiedAt { get; set;} public DateTime LastSyncedAt { get; set;} public User () { } } Have been able to create a collection and also to add users. How do I find users, whose LastModifiedAt timestamp is greater than LastSyncedAt timestamp ? Did

Expression tree is not supported on UpdateOneAsync

蓝咒 提交于 2019-12-11 07:45:52
问题 On calling UpdateOneAsync, with this wrapper: public async Task<UpdateResult> UpdateDocument<T>( string sCollectionName, Expression<Func<T, bool>> filter, UpdateDefinition<T> update, bool bUpsert, System.Threading.CancellationToken cancellationToken ) { IMongoDatabase db = _mongoClient.GetDatabase(_optionsMonitor.CurrentValue.databasename); IMongoCollection<T> collection = db.GetCollection<T>(sCollectionName); return await collection.UpdateOneAsync<T>(filter, update, new UpdateOptions() {

multiple document transaction not working in c# using mongodb 4.08 community server

你说的曾经没有我的故事 提交于 2019-12-11 07:36:32
问题 I need update multiple documents using mongodb transaction, mongodb community server version is 4.08, and mongodb driver for .net is 2.9 beta(also tried 2.8). From debugging, I can see it executed 'session.AbortTransaction();', but data was still inserted. var client = new MongoClient(_config.GetConnectionString(ProductMongoDBContext.DATABASE_CONNECTION_STRING)); var session = client.StartSession(); try { session.StartTransaction(); //var database = session.Client.GetDatabase

C# - MongoDB how to remove an item from multiple nested arrays by element value?

时间秒杀一切 提交于 2019-12-11 07:16:07
问题 I have this JSON structure in a mongo db collection: { "Id":"123", "Product": "test", "Tags":[ { "Name": "name", "Categories": [ { "Name": "test", "OtherValue": ... } ] }, { "Name": "name", "Categories": [ { "Name": "test", "OtherValue": ... } ] } ] } Is there a way to be able to remove an item from all of the nested "Categories" arrays by the item's "Name" property? For example, remove all categories where "Name" == "test" ? I tried something like this: var filter = Builders<Item>.Filter.Eq