mongodb-.net-driver

Rename field of complex type that is located in array

隐身守侯 提交于 2019-12-12 09:47:46
问题 I'm doing refactoring on production database and need to make some renamings. Version of mongodb is 1.8.0. I use C# driver to do refactoring of database. Have faced with problem when I try to rename field of complex type that is located in array. For example I have such document: FoobarCollection: { Field1: "", Field2: [ { NestedField1: "", NestedField2: "" }, { NestedField1: "", NestedField2: "" }, ... ] } I Need to rename NestedField2 into NestedField3 , for example. MongoDB documentation

How to create MongoDB MultiKey index on attribute of items in an array .NET Driver

旧巷老猫 提交于 2019-12-12 09:33:50
问题 I have a MongoDB collection "foos" containing items which each have an array of "bars". That is, "foo" has the following schema: { "id": UUID "name": string ... "bars": [ "id": UUID "key": string ... ] } I need to create an index on name and bar.key using the MongoDB C# .NET Mongo driver. I presumed I could use a Linq Select function to do this as follows: Indexes.Add(Context.Collection<FooDocument>().Indexes.CreateOne( Builders<FooDocument>.IndexKeys .Descending(x => x.Bars.Select(y => y.Key

Calling a Stored Procedure in MongoDB via C#

我只是一个虾纸丫 提交于 2019-12-12 07:24:39
问题 I have a saved function in system.js called "addNumbers" which has 2 parameters: function addNumbers( a , b ) { return a + b; } I wish to execute this function via C#, by adding 2 numbers which are inputted by a user. So far I have the following code: MongoClient client = new MongoClient(); MongoServer server = client.GetServer(); MongoDatabase test = server.GetDatabase("test"); Console.WriteLine("Input two numbers: "); string num1 = Console.ReadLine(); string num2 = Console.ReadLine();

How to exclude the _id field while retrieving and displaying data from MongoDB using C#

﹥>﹥吖頭↗ 提交于 2019-12-12 04:37:49
问题 How do i exclude the _id field from the set of fields returned in C#, there are posts on this website that mention of the .include() and .exclude() methods but those methods are not present in my case. below is the code where 'secondary' is a field in the outer document which is an array and '.amount' is the field nested within the 'secondary' array ( like a nested document ). Can someone help me out with this please..! var fields = "secondary.amount"; foreach (var document in collection

MongoDB c# 2.0.1 driver- connection suddenly closes

喜欢而已 提交于 2019-12-12 03:20:16
问题 Here's the full program code: (Except for Follower class which is only id and username - Json-type class) I don't have any users for db - just created simple collection class Program { static void Main(string[] args) { DBClass db = new DBClass(); db.check(); } } class DBClass { protected string connectionString ="mongodb://localhost:27017"; protected IMongoClient _client; protected IMongoDatabase _database; protected IMongoCollection<Follower> collection; public DBClass() { _client = new

Multiple filters via MongoDB C# driver

戏子无情 提交于 2019-12-11 23:35:25
问题 How runtime generate filters with official drivers? I want get contacts that contains specific user id and can be filtered for some properties (contains some text) Current code dont work with request.Filter > 1 : private FilterDefinition<Contact> BuildFilter(NgTableRequest request, string userId) { var filters = new List<FilterDefinition<Contact>> { Builders<Contact>.Filter.Where(q => q.ContactUsers.Any(w => w.UserId == userId)) }; if (request.Filter != null && request.Filter.Any()) { foreach

MongoDB Aggregation using official C# driver?

蹲街弑〆低调 提交于 2019-12-11 18:57:56
问题 I'm using the official C# driver.Have no idea to implement this: Select MAX(TimeStamp) as MaxTimeStamp, ExtNo From AgentStatus Where TimeStamp>=@begin and TimeStamp <=@end Group By ExtNo Any Help?Thanks! 回答1: Already use MapReduce to solve the problerm :) A simple demo HERE 来源: https://stackoverflow.com/questions/14917362/mongodb-aggregation-using-official-c-sharp-driver

MongoDB Error with C#

醉酒当歌 提交于 2019-12-11 18:17:57
问题 I have seen the Quickstart Windows and downloaded mongodb-win32-i386-2.0.4.zip and this error appears when I run mongo.exe: Error: couldn't connect to server 127.0.0.1 shell/mongo.js:84 exception: connect failed What should I do? Do I need to download something else? 回答1: mongo.exe is the Mongo Shell , which will attempt to connect to the server at localhost:27017 unless you explicitly specify another server and port. The one you're after is mongod.exe (notice the 'd'?), which is the MongoDB

Indexing parallel arrays in Mongodb

旧巷老猫 提交于 2019-12-11 17:52:16
问题 I am starting to use MongoDb C#, but have run into a slight issue. So I have a document with 2 embedded collections(of distinct types). I want to search on fields of both of these collections however I have discovered that if I try to index the searchable fields on the 2 collections I get "cannot index parallel arrays". Reading the Mongodb documentations on multikey indexes I discovered that this is indeed a limitation. My question is what is the normal work around regarding this issue? I

Build this LEFT() “SQL” in MongoDB Query?

风流意气都作罢 提交于 2019-12-11 13:11:48
问题 Have an BsonDocument collection with PhoneNumber in the "1234567890" format. This SQL gets all the PhoneNumbers with the Area Codes between 300 and 399; WHERE (LEFT(PhoneNumber,3) BETWEEN '300' AND '399') How would I do this in MongoDB? I would like to use the MongoDB.Driver.Builders if possible. 回答1: If you just want phone number that's starts from number '3' you can just use smart decision of @mstearn , here just c# realization: var query = Query.EQ("PhoneNumber", new BsonRegularExpression(