I want to implement "Update mytable set isdel = 1 where id = '000000 '"
I use the samus driver.
I will not talk about the link.
This is the data obtained from the query.
{ "_id" : ObjectId("4ed4a56912842309d072c2ef"), "id" : "123456789", "userid" : "10000", "tiitle" : "test", "content" :"testcontent", "isdel" : 0 }
public int Delete(string id) { Document doc = new Document(); doc["isdel"] = 1; using (MyMongoDb mdb = new MyMongoDb()) { var collection = mdb.GetCollection<LOGS>(); collection.Update(doc, x=>x.id=id); } return 1; }
The result is updated, but only one isdel field is left for the update of the entire row.
{ "_id" : ObjectId("4ed4a56912842309d072c2ef"), "isdel" : 1 }
public int Delete(string id) { Document doc = new Document(); doc["isdel"] = 1; using (MyMongoDb mdb = new MyMongoDb()) { var collection = mdb.GetCollection<LOGS>(); collection.FindAndModify(doc, new Document { { "id", id } }); } return 1; }
Check if there are any other methods. I have been searching for a long time and found the findandmodify method.
Run the command to check the result.
{ "_id" : ObjectId("4ed4a56912842309d072c2ef"), "id" : "123456789", "userid" : "10000", "tiitle" : "test", "content" :"testcontent", "isdel" : 1 }
Success.
This is the difference between update and findandmodify.