C#でのMongoDB更新操作


「update mytable set isdel=1 where id='123456789」を実現したい
私はsamusドライブを使っています
リンクは言わないで、ポイントを言います.
これはクエリーから出たデータです.
{ "_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;
        }


 
結果は更新されましたが、行全体が更新されisdelフィールドが1つしか残っていません.
{ "_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;
        }

 
他の方法があるかどうか見てみましょう.長い間探していましたが、FindAndModifyの方法です.
実行して、結果を見てください.
{ "_id" : ObjectId("4ed4a56912842309d072c2ef"), "id" : "123456789", "userid" : "10000", "tiitle" : "test", "content" :"testcontent", "isdel" : 1 }

 
成功、ほほほ.
これがUpdateとFindAndModifyの違いです.