how can I insert a document inside another document with mongodb ?
I’ve tried something like the code below but I always have a problem converting my list of setting in the field Settings:
var settingViewModels = new[]{ setting };
var query = Query.EQ("Name", applicationName);
var update = Update.AddToSet("Settings", BsonArray.Create(setting));
db.Collection<Applications>().Update(query, update, UpdateFlags.Upsert, SafeMode.True)
I got an error when I convert my settingViewModels into BsonArray saying:
.NET type MyProject.SettingViewModel cannot be mapped into BsonType.Array
Parameter name: value
Any idea ?
thanks
John
If you want add setting item to the Settings[] array of Application collection you should use
ToBsonDocument()extention method fromMongoDB.Bsonnamespace:You no need create
BsonArray.