i have one collection in which i am doing insert/update operation. for insert i use the code:
MongoCollection<BsonDocument> tblCity = mydb.GetCollection<BsonDocument>("tblCity");
BsonDocument CollectionCity = new BsonDocument {
{ "CityCode", cityCode },
{ "CityName", cityName },
{ "stamps" , new BsonDocument {
{"ins", DateTime.Now},
{"upd", ""},
{"createUsr", UserId},
{"updUsr", ""},
{"Ins_Ip", ""},
{"Upd_IP", GetIP()}
}
}
};
tblCity.Insert(CollectionCity);
it is working fine. but while i am updating i am using code:
MongoCollection <BsonDocument> tblCity = mydb.GetCollection<BsonDocument>("tblCity");
var query = new QueryDocument { { "City_strCode", cityCode } };
var update = new UpdateDocument {
{ "$set", new BsonDocument("City_strName", cityName) },
{ "stamps" , new BsonDocument{
{"upd", DateTime.Now},
{"updUsr", ""},
{"Upd_IP", GetIP()
}}
}};
tblCity.Update(query, update);
But problem is that with out changing the ins
date i want to update upd
field. But it is removing the ins
field and updating the upd
field. I am trying a lot of ways but not able to get any solution. Please suggest something....Even I got some links based on this and tried.. but none of them workout.