mongodb-.net-driver

Insert documents into MongoDB only if all fields are unique

佐手、 提交于 2019-12-14 02:37:15
问题 I have the following class structure: public class DBTestItem { public int p0; public int p1; public int p2; public int p3; public int p4; public int p5; public int p6; public int p7; public string data; } public sealed class MongoTestItem : DBTestItem { public ObjectId _id; } _id is meaningless to me. p0 - p7 represent a composite key, and data represents the value. I want to save MongoTestItem documents where data is unique, and ideally without performing updates as they would be

mongodb c# API V2: Difference between ReplaceOne and FindOneAndReplace

大兔子大兔子 提交于 2019-12-13 15:26:10
问题 Looking a the mongodb documentation I read that FindOneAndReplace would be an ATOMIC operation. But what I don't understand is why ReplaceOne wouldn't be atomic? And if there is a difference why should one use ReplaceOne at all? 回答1: I just found the answer here, which should be the same for replace. https://docs.mongodb.org/manual/reference/method/db.collection.findAndModify/#comparisons-with-the-update-method 来源: https://stackoverflow.com/questions/36895238/mongodb-c-sharp-api-v2-difference

How to fetch a list of values from a Bson document?

点点圈 提交于 2019-12-13 14:25:06
问题 I'm parsing in a Json document that stores a list of type <Country> (which holds the name and code ), using the MongoDB.Net driver. But I'm not sure how to retrieve that list of countries from the Bson document. I stepped through the parsing code, all values are being parsed in to the CountryModel. Then stored in the returned collection var. Googling brought me this solution but it only shows how to return a record by ID not a complete List. I'm wondering if a Lambda overload can be used here

Using Facets in the Aggregation Framework C# with Multiple Facet, Unwind and sortByCount

萝らか妹 提交于 2019-12-13 12:48:58
问题 How can I represent this pipeline in C# ? -----Id -----Name -----ProductAttributes (object array) | -----ProductAttributeType -----ProductAttributeValues (string array) My Collection: { "_id" : ObjectId("5b41a5e225cd892c14628b78"), "Name" : "Esmalte Super Pérola Fashion Glamour", "ProductAttributes" : [ { "ProductAttributeType" : "Coleção", "Values" : [ "Fashion" ] }, { "ProductAttributeType" : "Tamanho", "Values" : [ "8 ml" ] }, { "ProductAttributeType" : "Tom", "Values" : [ "Vermelho",

MongoDB troubleshooting on Windows (C#) (What to do?)

╄→гoц情女王★ 提交于 2019-12-13 07:24:44
问题 I have trouble with MongoDB on Windows 7 (32 bit). I make some tests with adding/deleting data. So after some time (i do not know how much, maybe 10 minutes of non-stopping requests) MongoDB server still works but not answers! From console shell I tried command "show collections", but it stucks! The size of storage at this moment was only 160 MBs. This trouble was yesterday and it was before not always, but from time to time. And only after restarting MongoDB works fine before next such

MongoDB query results ordering (Numeric Range query)

て烟熏妆下的殇ゞ 提交于 2019-12-13 07:04:15
问题 *Mongo newbie here (using Mongo C# Driver on Windows) Hi, I am evaluating Mongo for applying a combination of numeric dimensions . I have a hundreds of numeric fields and create a boolean query(I work extensively with Lucene, Solr etc hence pardon the terminology). The results in Solr are ordered by relevance i.e. closest match along the multiple dimensions, followed by the next closest, and so on.... For example: Doc1: - NumField 1 : 9.9 - NumField 2: 8.2 Doc2: - NumField 1 : 5.9 - NumField

MongoDb C# driver, property of type implementing IList not saving

僤鯓⒐⒋嵵緔 提交于 2019-12-13 05:08:57
问题 Changed the persistence layer of my web app to MongoDb using the C# drivers from the MongoDb site. Was pleasantly surprised to find all of my tests passing... except for one class. One of its properties is a type that implements IList and for some reason it doesn't save its items. I've built a minimal test case to illustrate. Here's the test code to create and save the parent object: var fooCollection = database.GetCollection<Foo>( typeof( Foo ).Name ); var foo = new Foo {Id = "Root"}; foo

Find an specific element in a MongoDB document from C#

别说谁变了你拦得住时间么 提交于 2019-12-13 04:43:25
问题 I am trying to access MongoDB from C# ASP.NET application. Let's assume, I've a document like below- { "_id" : ObjectId("546c776b3e23f5f2ebdd3b03"), "Name" : "Test", "Values" : [ { "Name" : "One", "Value" : 1 }, { "Name" : "Two", "Value" : 2, "Parameters": [{"Type": "Type A"}, {"Type": "Type B"}] } ] } Please note that, only the _id and Name elements are fixed; other elements are dynamically created by the user where both the key and value are defined by the user. Now, I would like to search

How to query/update sub document in MongoDB using C# driver

◇◆丶佛笑我妖孽 提交于 2019-12-13 00:45:47
问题 public class DayData { public string _id {get;set;} public string Data {get;set;} public HourData HR1 {get;set;} public HourData HR2 {get;set;} ... public HourData HR24 {get;set;} } public class HourData { public long _id {get;set;} public int Count {get;set;} public string Data {get;set;} } // Sample Data { "_id": "2012_11_10", "Data": "some data", "HR1": { "_id": 1 "Count": 100, "Data": "Hour 1 Data" }, "HR2": { "_id": 2 "Count": 200, "Data": "Hour 2 Data" }, ... "HR24": { "_id": 24 "Count"

mongodb c# select specific field dot notation

↘锁芯ラ 提交于 2019-12-13 00:44:03
问题 In addition for my previous question: mongodb c# select specific field. I'm writing a generic method for selecting a specific field. the requirements are: Field can be of any type Return type is T Field can be inside a sub field Field can be inside array items - in that case its OK to select the specific field of all the items in the array for shorts, im looking for the "select" / dot notation capability. for example: the wanted method: T GetFieldValue<T>(string id, string fieldName) the