How to convert BsonElement to BsonDocument in C#

475 views
Skip to first unread message

trypsin

unread,
Apr 29, 2012, 12:11:20 PM4/29/12
to mongodb-user
I have a question like this:

my current bson document is like this:

{
_id: ********************
VehicleType: StarType
BrakeSystem: X Layout
}

and now I hope to put more information in the field of BrakeSystem
like this:


{
_id: ********************
VehicleType: StarType
{ BrakeSystem: X Layout, ABS: BOSCH ABS6}
}

so how can I convert the BsonElement to BsonDocument data? or Just
delete the original BrakeSystem field and nest the new BrakeSystem
document?

craiggwilson

unread,
Apr 29, 2012, 4:05:28 PM4/29/12
to mongod...@googlegroups.com
You wouldn't really convert it.  You'd just overwrite it.

doc = collection.FindOne();

doc["BrakeSystem"] = new BsonDocument("BraokSystem", "X Layout").Add("ABS", "BOSCH ABS6");

collection.Save(doc);

trypsin

unread,
Apr 30, 2012, 9:46:35 AM4/30/12
to mongodb-user
thanks, i just tried, it works!
Reply all
Reply to author
Forward
0 new messages