【发布时间】:2012-09-22 03:44:48
【问题描述】:
我有此代码用于从 mongob 排序规则中删除项目
private MongoCollection<T> GetCollection()
{
connectionString = "mongodb://localhost/?safe=true";
server = MongoServer.Create(connectionString);
database = server.GetDatabase("CSCatalog");
return database.GetCollection<T>("myCollectionName");
}
public bool Delete(T entity)
{
var id = typeof(T).GetProperty("Id").GetValue(entity,null).ToString();
var query = Query.EQ("_id",id);
var finded = GetCollection().Find(query); // return null
var result= GetCollection().Remove(query, MongoDB.Driver.RemoveFlags.Single); // no errors, but don't remove
return esito.Ok; //return true but donn't remove.
}
GetCollection() 方法检索正确的集合,我已经对其宽度调试进行了测试。 在集合中有我要删除的项目,它与我在第一行检索到的 id 相同。
实体有一些字段和一个名为“Id”的 Objectid 字段
【问题讨论】:
-
会发生什么? “不起作用”不够具体。
标签: mongodb collections mongodb-.net-driver mongodb-query