MongoDB c# driver SetWrapped issue -


** updated more code:

i have class/entity similar

public class price     {         public decimal mrp { get; set; }  } 

this part of complex doc following:

{   "name" : "name",   "_id" : objectid("522a83c2a833e20db4b028ea"),    "price" : {     "mrp" : 599,   } } 

i using c# driver update doc ... following:

// function check if field exists in doc private bool check_field(bsondocument doc, string field_name) { if (doc.contains(field_name)) { return true; } else { return false; } }

// whole doc

foreach (var c in cursor)             {                 product prd = new product();                 prd.id = check_field(c.tobsondocument(), "id") ? converttostring(c.tobsondocument()["id"]) : null;                 prd.price = check_field(c.tobsondocument(), "price") ? jsonconvert.deserializeobject<price>(c.tobsondocument()["price"].tostring()) : null;                 products.add(prd);             }   (var = 0; < products.count(); i++)             {                 price price_list = new price();     price_list.mrp = 500;     mongodb.driver.builders.updatebuilder update = mongodb.driver.builders.update.setwrapped("price", (price)price_list);             } 

when execute command, expect $set command issued as

{ "$set" : { "price" : { "mrp" : 500 }}} instead { "$set" : { "price" : { "mrp" : "599" }}} 

any / pointer helpful

finally worked when changed data type double (or float). decimal 64 bit - mongo stores numberlong.


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -