Hello i got an issue with MongoDB model builder like example i have UserModel for adding or updating existing document in mongo
here is one BsonDocument
public BsonDocument Premium = new BsonDocument()
.Add("isPremium", false)
.Add("PremiumEnds", DateTime.Now)
.Add("Level", int.Parse("0"))
.Add("RatioText", double.Parse("1.0"))
.Add("RatioVoice", double.Parse("1.0"));
and if document like this exist in user document like in first screenshot here is an issue
if i add to this BsonDocument new Key/Value like
public BsonDocument Premium = new BsonDocument()
.Add("isPremium", false)
.Add("PremiumEnds", DateTime.Now)
.Add("Level", int.Parse("0"))
.Add("RatioText", double.Parse("1.0"))
.Add("RatioVoice", double.Parse("1.0"))
.Add("Key", "Value");
after getting user info and updating some values this will not change the Existing BsonDocument
but if i add to UserModel like public int Prestige { get; set; }
outside BsonDocument after updating user new row will appears in document
Getting User Function
public static async Task<UserMongo> GetUserAsync(ulong id)
{
var user = Users.Find(a => a.Id == id).FirstOrDefault();
if (user != null) return user;
user = await SignUp(id);
return user;
}
Updating User Function
public static async Task<bool> UpdateAsync(UserMongo user)
{
await Users.ReplaceOneAsync(a => a.Id == user.Id, user);
return await Task.FromResult(true);
}
What is the problem maybe someone has issue like this?
also tryed building model like this
[BsonIgnoreIfDefault]
public BsonDocument Premiums = new BsonDocument {
{ "isPremium", false },
{ "PremiumEnds", DateTime.Now },
{ "Level", int.Parse("0") },
{ "RatioText", double.Parse("1.0") },
{ "RatioVoice", double.Parse("1.0") }
};
After inserting for first time and adding new Key/Value to this BsonDocument after updating this document not apply new Key/Value inside BsonDocument