mongodb-.net-driver

Mongodb authentication [duplicate]

丶灬走出姿态 提交于 2019-12-01 08:43:56
问题 This question already has answers here : MongoDB GridFs with C#, how to store files such as images? (3 answers) Closed 6 years ago . How do I use authentication with mongodb via the official c# driver? I can't find any API methods to authenticate, other than internal members. 回答1: Authentication credentials should be specified in your connection string, using the following connection string format: mongodb://[username:password@]hostname[:port][/[database][?options]] See full details here in

MongoDb C# Typed Aggregations with Group Unwind and Project

走远了吗. 提交于 2019-12-01 08:38:39
I have a collection like this: [{ "_id": 1, "OtherProperties": 100 "PersonInventory": [{ "FirstName": "Joe", "MiddleName": "Bob", "LastName": "Blogs", "PersonId": 1 }] },{ "_id": 2, "OtherProperties": 1005 "PersonInventory": [{ "FirstName": "Joe", "MiddleName": "Bob", "LastName": "Blogs", "PersonId": 1 }] }] And I am trying to select all the unique persons in the root docs using here newer type inference mongodb c# driver syntax. Tried this so far but getting errors saying the method is not available (i think this is to do with the grouping), can anyone show me where I am going wrong?

MongoDB C# Get latest document from group

青春壹個敷衍的年華 提交于 2019-12-01 07:36:18
I have a group of statuses of pretend payments, each with a payment ID. I want to get the latest status for each payment ID. The test I have creates some dummy data and then tried to query it. I've got this far: [Test] public void GetPaymentLatestStatuses() { var client = new TestMongoClient(); var database = client.GetDatabase("payments"); var paymentRequestsCollection = database.GetCollection<BsonDocument>("paymentRequests"); var statusesCollection = database.GetCollection<BsonDocument>("statuses"); var payment = new BsonDocument { { "amount", RANDOM.Next(10) } }; paymentRequestsCollection

Getting a single object from mongodb in C#

久未见 提交于 2019-12-01 07:33:04
I've picked up a piece of code that is using the MongoDB driver like this to get a single object from a collection...this can't be right, can it? Is there a better way of getting this? IMongoCollection<ApplicationUser> userCollection; .... userCollection.FindAsync(x => x.Id == inputId).Result.ToListAsync().Result.Single(); Yes, there is. First of all don't use FindAsync , use Find instead. On the IFindFluent result use the SingleAsync extension method and await the returned task inside an async method: async Task MainAsync() { IMongoCollection<ApplicationUser> userCollection = ...; var

MongoDB: Date issue when before 1970

落花浮王杯 提交于 2019-12-01 06:51:49
问题 We are using MongoDB 2.4.9 (64 bits) over Windows 7 SP1 (64 bits). When we run the query below and we have any person in our collection with date of birth before the year of 1970 we get the exception "gmtime failed - your system doesn't support dates before 1970". db.persons.aggregate({ $project: { date: { year: { $year: "$DateOfBirth" }, month: { $month: "$DateOfBirth" }, day: { $dayOfMonth: "$DateOfBirth" } } } }) I've read in other threads that it's a known issue when running MongoDB on

Mongodb, linq driver. How to construct Contains with variable or statements

只愿长相守 提交于 2019-12-01 05:59:05
I'm using the Mongo LINQ Driver for C#, works great. Sorting a lot of properties but heres a problem I can't solve, its probably simple. var identifierList = new []{"10", "20", "30"}; var newList = list.Where(x => identifierList.Contains(x.Identifier)); This is NOT supported ... So I could do something like: var newList = list.Where(x => x.Identifier == "10" || x.Identifier == "20" || x.Identifier == "30"); But since the list is variable ... how do I construct the above? Or are there even better alternatives? The list is of type IQueryable<MyCustomClass> For information ... this is used as a

MongoDump query with BinData

亡梦爱人 提交于 2019-12-01 05:44:24
The Mongodump documentation specifies you can dump using a specific query i.e. mongodump --host localhost --db mydb --collection testCollection --query "{SomeKey: 'some value'}" I'm storing _ids fields as BinData, is it possible to query on this? I've tried mongodump --host localhost --db mydb --collection testCollection --query "{_id: 'BinData(3,ryBRQ+Px0kGRsZofJhHgqg==)'}" With no luck. This needs a lot of escaping, unfortunately. Also, you'll have to use the $binary representation instead, e.g. mongodump --host localhost --db test --collection bd --query "{\"_id\" : { \"$binary\" : \"ryBRQ

MongoDB C# Get latest document from group

旧巷老猫 提交于 2019-12-01 05:27:12
问题 I have a group of statuses of pretend payments, each with a payment ID. I want to get the latest status for each payment ID. The test I have creates some dummy data and then tried to query it. I've got this far: [Test] public void GetPaymentLatestStatuses() { var client = new TestMongoClient(); var database = client.GetDatabase("payments"); var paymentRequestsCollection = database.GetCollection<BsonDocument>("paymentRequests"); var statusesCollection = database.GetCollection<BsonDocument>(

Strange behavior of MongoDB LINQ provider for fields called “id”

Deadly 提交于 2019-12-01 04:00:20
Here's a JSON document where Mongo LINQ provider fails: {"results": {"text":"@twitterapi http://tinyurl.com/ctrefg", "to_user_id":396524, "to_user":"TwitterAPI", "from_user":"jkoum", "metadata": { "result_type":"popular", "recent_retweets": 109 }, "id":1478555574, "from_user_id":1833773, "iso_language_code":"nl", "source":"<a href=\"http://twitter.com/\">twitter<\/a>", "profile_image_url":"http://s3.amazonaws.com/twitter_production/profile_images/118412707/2522215727_a5f07da155_b_normal.jpg", "created_at":"Wed, 08 Apr 2009 19:22:10 +0000", "since_id":0, "max_id":1480307926, "refresh_url":"

Query near vs. within

随声附和 提交于 2019-12-01 03:58:42
问题 Using MongoDB I'm querying homes that are within 25 miles of a lat/long. My first attempt to do this used the near command, like so: var near = Query.Near("Coordinates", coordinates.Latitude, coordinates.Longitude, find.GetRadiansAway(), false); var query = Collection().Find(near); var listings = query.ToList(); The issue with near is that it only returns 100 listings, whereas I want to return all listings within 25 miles of the coordinates. My next attempt was to use within: var within =