How do you increment a field in mongodb using c#

眉间皱痕 提交于 2019-11-30 20:46:39

Not sure what your helper does. Here is a working snippet I use:

        var query = Query.And(Query.EQ("_id", keyName));
        var sortBy = SortBy.Null;
        var update = Update.Inc("KeyValue", adjustmentAmount);
        var result = collection.FindAndModify(query, sortBy, update, true);

So, "query" finds the document, update does the increment, and FindAndModify puts them together and actually hits the database.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!