This is the C# code I have written for updating a record in MongoDB:
public static void updateSubmit(string id,string fname,string lname,string email,string password,string address)
{
string connectionString = "mongodb://10.10.32.125:27017";
MongoClientSettings settings = MongoClientSettings.FromUrl(new MongoUrl(connectionString));
MongoClient mongoClient = new MongoClient(settings);
var Server = mongoClient.GetDatabase("mongovaibhav");
var collection = Server.GetCollection<employee>("mongov");
ObjectId objectId = ObjectId.Parse(id);
var filter = Builders<employee>.Filter.Eq(s => s._id, objectId);
employee emp = new employee();
emp.fname = fname;
emp.lname = lname;
emp.email = email;
emp.pass = password;
emp.address = address;
collection.ReplaceOneAsync(filter, emp);
}
Below is my Ajax code used for sending an update request along with data:
function updateSubmit()
{
$.ajax({
type: 'POST',
contentType: "application/json; charset=utf-8",
url: 'Home.aspx/updateSubmit',
data: "{'id':'" + $("#hidden").val()+ "','fname':'" + $("#fname").val() + "','lname':'" + $("#lname").val() + "','email':'" + $("#email").val() + "','password':'" + $("#password").val() + "','address':'" + $("address").val() + "'}",
async: false,
success: function (response) {
alert("You Have SuccessFully Update Data");
},
error: function () {
console.log('there is some error');
}
});
}
I am facing an issue where I receive the alert message indicating successful record update, but the changes are not reflected in the database.