mongodb-.net-driver

c# mongodb case sensitive search

匆匆过客 提交于 2019-12-10 00:43:08
问题 I have a collection in which I store Email and password of user. I obviously don't want to require the user to insert his email case sensitive and to be exactly as when he first registered. I'm using mongodb 2.0 c# driver, I'm repeating it because I saw solutions to queries written with regex but I'm afraid I cant user it in here. my query looks like var filter = Builders<ME_User>.Filter.And( Builders<ME_User>.Filter.Eq(u => u.Email, email), Builders<ME_User>.Filter.Eq(u => u.Password,

MongoDB Optimistic Concurrency Control With .NET

爱⌒轻易说出口 提交于 2019-12-09 17:43:00
问题 Using the .NET MongoDB API (MongoDB.Driver), what is the recommended approach for implementing optimistic concurrency control? For example, is there anything analogous to SQL Server's ROWVERSION/TIMESTAMP, e.g., a property that is automatically updated whenever the document changes? Or is there a trigger mechanism? Or any other mechanism? 回答1: There isn't anything built-in regarding optimistic concurrency in MongoDB. You need to implement that yourself if you need it. You can do that by

Using Facets in the Aggregation Framework C#

强颜欢笑 提交于 2019-12-09 13:56:14
问题 I would like to create an Aggregation on my data to get the total amount of counts for specific tags for a collection of books in my .Net application. I have the following Book class. public class Book { public string Id { get; set; } public string Name { get; set; } [BsonDictionaryOptions(DictionaryRepresentation.Document)] public Dictionary<string, string> Tags { get; set; } } And when the data is saved, it is stored in the following format in MongoDB. { "_id" : ObjectId(

Deserializing field when type is changed using MongoDb csharp driver

半世苍凉 提交于 2019-12-09 09:37:23
问题 I am testing a number of scenarios with MongoDb to see how to recover from possible data issues. I have classes (Addresses with collection of Address) with a zipcode property in Address which was originally cast as string. I saved out multiple records of Addresses and could retrieve them all fine. like this, var allAddresses = addresses.FindAllAs(); I changed the zip code property to int and saved some records. I then changed the zip code property back to string. When I attempt to read the

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

纵然是瞬间 提交于 2019-12-08 19:43:33
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 from the 4 sub documents having a date of 9th Jan 2015, the query above also returns sub documents whose

What is the optimum bulk item count with InsertBatch method in mongodb c# driver?

烈酒焚心 提交于 2019-12-08 19:32:03
问题 I heard that large batch sizes don't really give any additional performance what is the optimum? 回答1: If you call Insert to insert documents one at a time there is a network round trip for each document. If you call InsertBatch to insert documents in batches there is a network round trip for each batch instead of for each document. InsertBatch is more efficient than Insert because it reduces the number of network round trips. Suppose you had to insert 1,000,000 documents, you could analyze

cannot do asqueryable on mongodb collection

时间秒杀一切 提交于 2019-12-08 16:58:58
问题 I got two models, a User and a Team as below: [BsonRepresentation(BsonType.ObjectId)] public ObjectId _id { get; set; } [Display(Name = "Password:")] public string Password { get; set; } [Display(Name = "Confirm:")] public string ConfirmPassword { get; set; } [Display(Name = "Email:")] public string Email { get; set; } [Display(Name = "Username:")] public string UserName { get; set; } [Display(Name = "Firtname:")] public string Firstname { get; set; } [Display(Name = "Lastname:")] public

Unwind then Group aggregation in MongoDB C#

霸气de小男生 提交于 2019-12-08 16:05:16
问题 I'm having some trouble with the new C# 2.0 MongoDB driver and the aggregation pipeline. Basically, I'm trying to return the most popular elements within an array field on the object. The field type is: IList<string> FavouritePlaceIds { get; set; } . I have the following MongoDB aggregation which is working as expected: db.users.aggregate([ { $unwind : "$FavouritePlaceIds" }, { $group: { "_id": "$FavouritePlaceIds", "count": {$sum: 1}}}, { $sort : { "count": -1 }} ]) However, the issue is now

When should i be opening and closing MongoDB connections?

岁酱吖の 提交于 2019-12-08 15:29:25
问题 i am very new to MongoDB and NoSQL in general and i've just started building a site with MongoDB / Norm / ASP.NET MVC 3. I am wondering how i should be scoping the connections to my Mongo database. Right now i have a Basecontroller that instanciates the MongoSession and onActionExecuted i dispose it so all my deriving controllers will have access to my MongoSession. The MongoSession class opens a connection in its constructor and disposes it on Dispose(), the way it's working today. private

How to do findAll in the new mongo C# driver and make it synchronous

蓝咒 提交于 2019-12-08 14:30:26
问题 I was using official C# driver to do a FindAll and upgraded to the new driver 2.0. FindAll is obsolete and is replaced with Find. I am trying to convert a simple method that returns me a list of Class1 . Cant find a realistic example using a POCO in their documentation var collection = database.GetCollection<ClassA>(Collection.MsgContentColName); return collection.FindAll().ToList(); Can someone please help me convert with 2.0 driver and return a list and not a task? 回答1: you could do this to