mongodb-.net-driver

MongoDB substring product search order by highest match

℡╲_俬逩灬. 提交于 2019-12-04 19:03:55
I'm not so good in Mongodb. That's my first project using this. I'm working on some sort of shop website. We're using C# and newest C# driver for mongodb. I need an idea how to implement my algorithm to filter products based on user's input. Here's how my algorithm works/should work. User type something like "Blue adidas men spiderman cotton t-shirt" I split whole phrase into single words so I have "blue", "adidas", "men", "spiderman", "cotton", "t-shirt" I check each word against retailer, color, category names in my db. So here's how it goes. "Blue" - oh, it's a color filter let's filter

storing a scanned (pdf,tiff,jpeg) file in MongoDB .

耗尽温柔 提交于 2019-12-04 17:45:25
I have to store a tiff(tag image file format) or pdf scanned file in mongodb that should be Text search able . like if we want to search "on base of text" it should be able to search . I am going to use .net mvc or java with mongodb . so how can i store this pdf file and then can retrieve from database . any suggestion will be appreciated . thanks shA.t You can store files by using MongoDb GridFs as described in this question and extract texts from a PDF file by using some features those described in this question . ;). HTH I think that you should save the files on file system of the server

Serializing Immutable Value types with Mongo C# Driver

吃可爱长大的小学妹 提交于 2019-12-04 17:20:58
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 should be taking? I assume you mean an EmailAddress class something like this: [BsonSerializer(typeof

Insert new document using InsertOneAsync (.NET Driver 2.0)

孤街醉人 提交于 2019-12-04 15:56:44
In the older .Net API version : MongoClient client = new MongoClient(); var server = client.GetServer(); var db = server.GetDatabase("foo"); var collection = db.GetCollection<BsonDocument>("bar"); var document = new BsonDocument { { "_id", 1 }, { "x", 2 } }; collection.Save(document); It worked. When i use new .Net Driver 2.0 : var client = new MongoClient("mongodb://localhost:27017"); var database = client.GetDatabase("foo"); var collection = database.GetCollection<BsonDocument>("bar"); var document = new BsonDocument { { "_id", 1 }, { "x", 2 } }; await collection.InsertOneAsync(document);

Connect to MongoDB failed when using .NET Core running on Linux

ぐ巨炮叔叔 提交于 2019-12-04 15:10:38
问题 I'm building a website using ASP.NET Core 2.0 (just upgraded from 1.1 one month ago). MongoDB is hosted by Mongo Atlas on AWS as well.This MongoDB instance has 3 replica set, require SSL to connect and already set can be access from any IP. It runs quite ok on my machine (Windows 10 x64) and AWS (Windows Server 2016). I try to deploy it on Linux machines, I use apt to install dotnet-runtime-2.0.0 on Ubuntu Server 16.04, then I try to run my site , and got the following error (for security

MongoDB atomic update via 'merge' document

穿精又带淫゛_ 提交于 2019-12-04 13:49:30
问题 I know that I can atomically update an existing Mongo document by setting specific fields. The following code will do it: var update = MongoDB.Driver.Builders.Update.Set("InsideLegMeasurement", 32.4); SafeModeResult result = personCollection.Update(query, update, UpdateFlags.Multi,SafeMode.True); However, can I atomically update several fields by passing in a document that I want to 'merge' with the existing doc? Imagine I have a document as follows: {"favcolor":"red","favfood":"pasta"} and I

Inheritance in MongoDb: how to request instances of defined type

痞子三分冷 提交于 2019-12-04 13:40:08
问题 This is how I used to utilize inheritance in Entity Framework (POCO): ctx.Animals // base class instances (all instances) ctx.Animals.OfType<Cat> // inherited class Cat's instances only ctx.Animals.OfType<Dog> // inherited class Dog's instances only This is the only similar way I found in MongoDb (MongoDb reference): var query = Query.EQ("_t", "Cat"); var cursor = collection.FindAs<Animal>(query); Note in the latter case I have to deal with discriminator ("_t") and hardcode my class name,

How to decorate a class item to be an index and get the same as using ensureIndex?

扶醉桌前 提交于 2019-12-04 12:31:36
I'd like to define in class declaration which items are index, something like: public class MyClass { public int SomeNum { get; set; } [THISISANINDEX] public string SomeProperty { get; set; } } so to have the same effect as ensureIndex("SomeProperty") Is this possible? I think this is a nice idea, but you have to do this yourself, there's no built-in support for it. If you have an access layer you can do it in there. You'd need an attribute class, something like this; public enum IndexConstraints { Normal = 0x00000001, // Ascending, non-indexed Descending = 0x00000010, Unique = 0x00000100,

MongoDB geospatial index in C#

自闭症网瘾萝莉.ら 提交于 2019-12-04 09:51:24
I have been trying to get started but run into the same rock time after time trying to create and query MongoDB with C# official driver. The problem is how to create data with geo information. I am just not finding the answer. Code: MongoUrl url = new MongoUrl("mongodb://xxx.xx.x.xx/mydb"); MongoServer server = MongoServer.Create(url); MongoDatabase database = server.GetDatabase("mydb"); <-- this works fine BsonDocument[] batch = { new BsonDocument { { "name", "Bran" }, { "loc", "10, 10" } }, new BsonDocument { { "name", "Ayla" }, { "loc", "0, 0" } } }; places.InsertBatch(batch); <-- that part

Runtime creation of LINQ expression

对着背影说爱祢 提交于 2019-12-04 06:49:40
Say I have this expression: int setsize = 20; Expression<Func<Foo, bool>> predicate = x => x.Seed % setsize == 1 || x.Seed % setsize == 4; This basically 'partitions' a set of elements into 20 partitions and retrieves from each set each first and fourth element. This expression is passed to MongoDB which it's driver is perfectly capable of translating into a MongoDB "query". The predicate can, however, also be used on a list of objects (LINQ2Objects) etc. I want this expression to be reusable ( DRY ). However, I want to be able to pass in an IEnumerable<int> to specify which items to retrieve