mongodb-.net-driver

How do I use in $in operator using the 2.0 version of the C# mongodb driver?

你说的曾经没有我的故事 提交于 2020-01-03 21:14:31
问题 I found a lot of examples of how do use $in in the previous mongodb c# driver, but I can not find any examples on how to do it in the 2.0 version. 回答1: Use the AnyIn operator for the typed version: Builders<TDocument>.Filter.AnyIn(x => x.Array,searchArray) 回答2: I was able to figure it out. Here is how to define the Bson document for the Find method: BsonDocument bson = new BsonDocument("_id", new BsonDocument("$in", new BsonArray(vins))); 回答3: Or, how about this var ft = new BsonDocument(

Mongodb - how to deserialze when a property has an Interface return type

让人想犯罪 __ 提交于 2020-01-03 20:58:49
问题 I'm attempting to avoid introducing any dependencies between my Data layer and client code that makes use of this layer, but am running into some problems when attempting to do this with Mongo (using the MongoRepository) MongoRepository shows examples where you create Types that reflect your data structure, and inherit Entity where required. Eg. [CollectionName("track")] public class Track : Entity { public string name { get; set; } public string hash { get; set; } public Artist artist { get;

Update with AddToSet not updating null value with MongoDB C#

ぃ、小莉子 提交于 2020-01-03 09:56:13
问题 Using MongoDB, I'm having trouble adding en element to an Array when the array is null. AddToSet works as expected if I add the item from the console. I am using the official C# driver from 10gen. var query = Query.EQ("_id", objectId); var itemDoc = item.ToBsonDocument(); //items is an array but currently null var update = MongoDB.Driver.Builders.Update.AddToSet("items", itemDoc); // YUNoWork? //somefield doesn't exist var workingUpdate = MongoDB.Driver.Builders.Update.AddToSet("somefield",

MongoDB retrieve only matching sub documents from a document with c#

99封情书 提交于 2020-01-03 02:00:32
问题 I want the following query below to only return those sub documents from the empActivity array where the Stamp field in every sub document matches the Stamp value in the query. empId and empActivity are the outer level fields with empActivity having embedded documents. db.emp_activity.find({$and : [{"empId" : "999"}, {"empActivity.Stamp" : { $lte : ISODate("2015-01-09T12:33:39.927Z")}}]}) The problem is that it also returns all the sub documents that dont match the date in the query, apart

Efficient way of paging with MongoDB and ASP.NET MVC

社会主义新天地 提交于 2020-01-02 10:13:13
问题 We are creating an application MongoDB as database and we are using official C# driver for MongoDB. We have one collection which contains thousands of records and we want to create list with paging. I have gone through documentation but there is not efficient way of paging with MongoDB C# official driver. My requirement is to exactly fetch only 50 records from database. I have seen many examples but that get all collection and perform skip and take via LINQ which is not going to work in our

Efficient way of paging with MongoDB and ASP.NET MVC

前提是你 提交于 2020-01-02 10:13:05
问题 We are creating an application MongoDB as database and we are using official C# driver for MongoDB. We have one collection which contains thousands of records and we want to create list with paging. I have gone through documentation but there is not efficient way of paging with MongoDB C# official driver. My requirement is to exactly fetch only 50 records from database. I have seen many examples but that get all collection and perform skip and take via LINQ which is not going to work in our

Efficient way of paging with MongoDB and ASP.NET MVC

自闭症网瘾萝莉.ら 提交于 2020-01-02 10:12:50
问题 We are creating an application MongoDB as database and we are using official C# driver for MongoDB. We have one collection which contains thousands of records and we want to create list with paging. I have gone through documentation but there is not efficient way of paging with MongoDB C# official driver. My requirement is to exactly fetch only 50 records from database. I have seen many examples but that get all collection and perform skip and take via LINQ which is not going to work in our

Full text search in mongodb in .net

℡╲_俬逩灬. 提交于 2020-01-02 03:15:09
问题 I have to search contents in all documents in particular collection of mongodb in .net mvc . I have tried with mongodb shell by creating index successfully like here . db.collection_name.createIndex( { subject: "text" } ) db.collection_name.find( { $text: { $search: "search_word" } } ) It works fine . but when i put it in .net that gives me error . I googled it and got following solution for indexing . collection.EnsureIndex(new IndexKeysBuilder().Ascending("subject")); now how can i run this

System.FormatException' occurred in MongoDB.Bson.dll - XXX is not a valid 24 digit hex string

 ̄綄美尐妖づ 提交于 2020-01-02 01:36:47
问题 I have created a C# class like this: public class Employee { [BsonRepresentation(BsonType.ObjectId)] public string Name { get; set; } public int Age { get; set; } public List<string> Address { get; set; } } When I try to save this information (using MongoDB) like this: var e = new Employee(); e.Address = new List<string>(); e.Address.Add("Address 1"); e.Address.Add("Address 2"); e.Age = 333; e.Name = "Some Name"; context.Employees.Insert(e); I am getting following error: An unhandled

Serializing Immutable Value types with Mongo C# Driver

て烟熏妆下的殇ゞ 提交于 2020-01-01 18:17:15
问题 I have many immutable value type classes, for example EmailAddress , which ensure any non null instance is valid. I would like to control the serialization of these types of objects to be just the standard string representation ( "123@abc.com" ) when persisted using MongoDB C# Driver. I have tried implementing the IBsonSerilizer however it will only allow for objects or arrays at the root level. I was able to implement proper Json Serilization with Json.NET, is there a different approach I