i’m creating a simple document manager for a dummy Project
for now i have Insert and Update methods
public ObjectId Insert(T model)
{
_collection.Insert(model);
return model.Id;
}
public void Update(T model)
{
var query = Query.EQ("_id", model.Id);
var bson = model.ToBsonDocument();
bson.Remove("_id");
var update = new UpdateDocument
{
{ "$set" , bson }
};
_collection.Update(query, update);
}
this is a proper way to doing this?. I’m newbie with mongo and mongocsharpdriver. i’m having problems saving properties like List<>
The easiest way to save a document back to the database is to use the Save method:
This does result in the entire document being sent to the server, so if you know that only a few fields are changing you can use Update.Set to change just those fields.
See online documentation at:
http://www.mongodb.org/display/DOCS/CSharp+Driver+Tutorial#CSharpDriverTutorial-Save%3CTDocument%3Emethod
http://www.mongodb.org/display/DOCS/CSharp+Driver+Tutorial#CSharpDriverTutorial-Updatemethod