mongodb-.net-driver

'IdentityContext' could not be found (are you missing a using directive or an assembly reference)

时间秒杀一切 提交于 2019-12-08 12:22:43
问题 I am migrate the project https://github.com/attilah/AngularJSAuthentication to using mongodb driver verson 2 , and I am in the final step here: namespace AngularJSAuthentication.API { using AspNet.Identity.MongoDB; using Entities; using MongoDB.Driver; public class ApplicationIdentityContext : IdentityContext { public ApplicationIdentityContext(IMongoContext mongoContext) : this(mongoContext.Users, mongoContext.Roles) { } public ApplicationIdentityContext(IMongoCollection<User> users,

How do you do SQL Like operator in mongoDB using the official C# driver

匆匆过客 提交于 2019-12-08 11:13:23
问题 How do you do the following SQL query in mongodb using the official c# Driver? Select * from tblUser where FirstName Like '%as%' 回答1: I figured out how to do this. You have to use Query.Matches var query = Query.Matches("FirstName", ".*as.*"); 回答2: I'd suggest you visit this site. It has a wealth of material on the official C# driver from 10gen. http://www.mongodb.org/display/DOCS/CSharp+Driver+Tutorial Most answer will just reproduce what is available on the link above. If you have a

C# Dynamic Linq Query with Fluent Mongo - Without using Contains or PredicateBuilder

删除回忆录丶 提交于 2019-12-08 07:52:56
问题 I'm using Fluent Mongo and having issues creating a dynamic linq query because Fluent Mongo doesn't support Contains. I basically need to have a nested OR statement within my Where to check if an Enum matches a list of enums. I'm sure there's another way to do this without using Contains, I just don't know enought about linq... I'm assuming I need to separate the linq expressions out and add them dynamically but I can't figure it out. I've tried using Dynamic Linq (ScottGu) but that doesn't

MongoDB Unable to determine the serialization information for the expression error

早过忘川 提交于 2019-12-08 07:16:40
问题 My data is having following structure public enum ParamType { Integer=1, String=2, Boolean=3, Double=4 } public class Gateway { public int _id { get; set; } public string SerialNumber { get; set; } public List<Device> Devices { get; set; } } public class Device { public string DeviceName { get; set; } public List<Parameter> Parameters { get; set; } } public class Parameter { public string ParamName { get; set; } public ParamType ParamType { get; set; } public string Value { get; set; } } I

Retrieve Relevance Ordered Result from Text Query on MongoDB Collection using the C# Driver

守給你的承諾、 提交于 2019-12-08 03:13:41
问题 I am attempting to text query a collection and retrieve the results in the text match order. The docs explain pretty well how to do this in the shell: db.articles.find( { status: "A", $text: { $search: "coffee cake" } }, { score: { $meta: "textScore" } } ).sort( { date: 1, score: { $meta: "textScore" } } ) but it requires the projection of the additional score field from the find into the sort. In C#, I have a function that looks like this: public IEnumerable<T> TextSearch<T>(MongoCollection

MongoDB C# Array index or indexing inner items of arrays

╄→гoц情女王★ 提交于 2019-12-08 03:02:20
问题 I use a dynamic array storage key, value, type in dynamicArray. MongoDB/C# generaly use an index of the array like db.contents.ensureIndex ( { dynamicArray : 1 } ). Storing more than 30 or 40 elements are generating a big information to index using this method. Exist another way to index not the complete array but items key of this array limiting the index storage. Something like -> Index key:Name, Index key:City and not all. dynamicArray: { item : { Key: "Name", Value: "Peter", Type:String }

MongoDB 2.4's “Limit Number of Elements in an Array after an Update” using C# driver?

一曲冷凌霜 提交于 2019-12-08 02:58:27
问题 MongoDB 2.4 added a new "Limit Number of Elements in an Array after an Update" feature. This is how it can be used through the shell: db.students.update( { _id: 1 }, { $push: { scores: { $each : [ { attempt: 3, score: 7 }, { attempt: 4, score: 4 } ], $sort: { score: 1 }, $slice: -3 } } } ) How can this be accomplished with the MongoDB's C#-driver? 回答1: Here is an example test that shows how to do this without using typed classes: https://github.com/mongodb/mongo-csharp-driver/blob/master

How to force mongo to store members in lowercase?

杀马特。学长 韩版系。学妹 提交于 2019-12-07 18:38:50
问题 I have a collection of BsonDocuments, for example: MongoCollection<BsonDocument> products; When I do inserts into the collection, I want the member name to always be lowercase. After reading the documentation, it appears that ConventionPack is the way to go. So, I've defined one like this: public class LowerCaseElementNameConvention : IMemberMapConvention { public void Apply(BsonMemberMap memberMap) { memberMap.SetElementName(memberMap.MemberName.ToLower()); } public string Name { get { throw

Why does my multithreaded insert perform better than a single threaded insert?

浪尽此生 提交于 2019-12-07 17:52:06
问题 I looked into concurrency in MongoDB, and apparently it uses a database level locking system. I thought that would mean that multiple threads inserting into the same database would perform similarly or worse than a single thread inserting into the database. I found that when I got to 4 threads concurrently inserting into the database, performance nearly doubled (in terms of inserts/sec). Is there any reason for why performance is getting better? I don't understand why. If it helps, I have one

C# MongoDb serialization of Dictionary<string, object>

蓝咒 提交于 2019-12-07 17:16:48
问题 I have a collection in my database where I log events. Each type of event has a different set of data. I've defined this with the following class: [CollectionName("LogEvent")] public class LogEvent { public LogEvent(string eventType) { EventType = eventType; EventData = new Dictionary<string, object>(); } public string EventType { get; private set; } [BsonExtraElements] public IDictionary<string, object> EventData { get; private set; } } Now - this works pretty good to some extent. As long as