问题描述
可有人请告诉我,如果有更好的方法来删除一个文件
从MongoDB中使用的比我下面的 -
Can someone please show me, if there is a better way to remove one document
from MongoDB using the Official C# Driver than what I have below-
var query = Query.EQ("_id", a.Id);
database.GetCollection<Animal>("Animal").Remove(query);
这个代码的工作,但似乎的的工作太多了的给我。为示例 - 保存命令将一个实例,并更新它。我想要的东西,喜欢 - 删除(项目)
This code works, but seems too much work to me. The "Save" command for example- takes an instance and updates it. I want something like- Remove(item)
.
备注:我试图用C#的,而不是或的这似乎已经过时了。
Remarks: I'm trying to use the official driver of C# rather than NoRM or Samus which seems out of date.
推荐答案
这是你做的方式。我敢肯定,你知道这一点,但是如果你想要把它放在同一行,所以你并不需要定义一个查询变量,你可以结合起来:
That's the way you do it. I'm sure you know this, but if you want to put it on one line you could combine it so you don't need to define a query variable:
collection.Remove(Query.EQ("_id", a.Id));
这篇关于如何删除使用MongoDB的官方C#驱动'ID'一'文件'?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!