mongodb-.net-driver

MongoDB GridFs with C#, how to store files such as images?

百般思念 提交于 2019-11-26 18:16:45
I'm developing a web app with mongodb as my back-end. I'd like to have users upload pictures to their profiles like a linked-in profile pic. I'm using an aspx page with MVC2 and I read that GridFs library is used to store large file types as binaries. I've looked everywhere for clues as how this is done, but mongodb doesn't have any documentation for C# api or GridFs C#. I'm baffled and confused, could really use another set of brains. Anyone one know how to actually implement a file upload controller that stores an image uploaded by a user into a mongodb collection? Thanks a million! I've

Convert string into MongoDB BsonDocument

丶灬走出姿态 提交于 2019-11-26 17:36:06
问题 I have a long string in JSON format, and I want to convert it into a BSONDocument for insertion into a MongoDB database. How do I do the conversion? I'm using the official C# driver. 回答1: The answer is: string json = "{ 'foo' : 'bar' }"; MongoDB.Bson.BsonDocument document = MongoDB.Bson.Serialization.BsonSerializer.Deserialize<BsonDocument>(json); 回答2: string json = "{ 'foo' : 'bar' }"; BsonDocument document = BsonDocument.Parse(json); 回答3: Using Version 2.1 of MongoDB's .NET library string

How to replace substring in mongodb document

馋奶兔 提交于 2019-11-26 17:33:54
I have a lot of mongodb documents in a collection of the form: { .... "URL":"www.abc.com/helloWorldt/..." ..... } I want to replace helloWorldt with helloWorld to get: { .... "URL":"www.abc.com/helloWorld/..." ..... } How can I achieve this for all documents in my collection? Naveed db.media.find({mediaContainer:"ContainerS3"}).forEach(function(e,i) { e.url=e.url.replace("//a.n.com","//b.n.com"); db.media.save(e); }); Louisa Currently, you can't use the value of a field to update it. So you'll have to iterate through the documents and update each document using a function. There's an example

MongoDB C# Driver 2.0 - Update document

感情迁移 提交于 2019-11-26 16:25:42
问题 I'm currently upgrading my code to MongoDB C# driver 2.0 and I'm having issues upgrading the code to update documents. using the old version I was able to do something like this: MyType myObject; // passed in var collection = _database.GetCollection<MyType>("myTypes"); var result = collection.Save(myObject); I'm struggling to find a way to do this in the new version. I have found a few examples of updating single fields like var filter = Builders<MyType>.Filter.Eq(s => s.Id, id); var update =

MongoDB GridFs with C#, how to store files such as images?

烈酒焚心 提交于 2019-11-26 08:54:53
问题 I\'m developing a web app with mongodb as my back-end. I\'d like to have users upload pictures to their profiles like a linked-in profile pic. I\'m using an aspx page with MVC2 and I read that GridFs library is used to store large file types as binaries. I\'ve looked everywhere for clues as how this is done, but mongodb doesn\'t have any documentation for C# api or GridFs C#. I\'m baffled and confused, could really use another set of brains. Anyone one know how to actually implement a file

MongoDB C# 2.0 TimeoutException

梦想的初衷 提交于 2019-11-26 08:37:35
问题 We\'ve recently upgraded our web application to MongoDB C# Driver 2.0 and deployed to production. Below a certain load, the application runs fine. Once the load on the production server exceeds a certain limit, the CPU of the application instantly falls down to 0 and after about 30 seconds, this exception is logged several times: System.TimeoutException message: A timeout occured after 30000ms selecting a server using CompositeServerSelector{ Selectors = ReadPreferenceServerSelector{

Aggregate $lookup with C#

大兔子大兔子 提交于 2019-11-26 08:32:06
问题 I have the following MongoDb query working: db.Entity.aggregate( [ { \"$match\":{\"Id\": \"12345\"} }, { \"$lookup\": { \"from\": \"OtherCollection\", \"localField\": \"otherCollectionId\", \"foreignField\": \"Id\", \"as\": \"ent\" } }, { \"$project\": { \"Name\": 1, \"Date\": 1, \"OtherObject\": { \"$arrayElemAt\": [ \"$ent\", 0 ] } } }, { \"$sort\": { \"OtherObject.Profile.Name\": 1 } } ] ) This retrieves a list of objects joined with a matching object from another collection. Does anybody

MongoDB .Net driver 2.0 Pull (remove element)

ぐ巨炮叔叔 提交于 2019-11-26 08:24:24
问题 Can you help me to run correctly \"Pull (remove)\" with 2.0 driver. I have a collection like this and I want to remove first follower named as fethiye by follower field. { \"_id\": ObjectId(\"554e05dfc90d3d4dfcaa2aea\"), \"username\": \"bodrum\", \"followerList\": [ { \"_id\": ObjectId(\"554e0625a51586362c33c6df\"), \"follower\": \"fethiye\", \"avatar\": \"fethiye.png\" }, { \"_id\": ObjectId(\"554e0625a51586362c33c6df\"), \"follower\": \"izmir\", \"avatar\": \"izmir.png\" } ] } How can I fix

How does MongoDB deal with concurrent updates?

岁酱吖の 提交于 2019-11-26 07:43:42
问题 I started to use MongoDB at work so far so good. I was wondering though how does MongoDB deal with concurrent updates ? I\'ve read that there is no locking feature in MongoDB so I was wondering what is the the common practice to deal with this. Thanks. 回答1: MongoDB used a process wide write lock to guarantee that only one write operation (update/insert/remove) can be performed at a time. As such it automatically solves concurrency issues since write concurrency simply isn't allowed. If 4

How to replace substring in mongodb document

守給你的承諾、 提交于 2019-11-26 04:46:08
问题 I have a lot of mongodb documents in a collection of the form: { .... \"URL\":\"www.abc.com/helloWorldt/...\" ..... } I want to replace helloWorldt with helloWorld to get: { .... \"URL\":\"www.abc.com/helloWorld/...\" ..... } How can I achieve this for all documents in my collection? 回答1: db.media.find({mediaContainer:"ContainerS3"}).forEach(function(e,i) { e.url=e.url.replace("//a.n.com","//b.n.com"); db.media.save(e); }); 回答2: Starting Mongo 4.2 , db.collection.update() can accept an