利用C# 驱动删除mongo中 list中的 某一项

mongodb中存储的结构如下:

public class questionInfo
{
public int _id { get; set; } //试题id
public List<questionSameInfo> Samequestions { get; set; } //与该题分词相似的试题集合
public List<questionSameInfo> SameBody { get; set; } //与该题文本相似的试题集合
public int Hasimg { get; set; } //是否有图片,1为是,0为否
public string Ways { get; set; } //解析
public int Waysize { get; set; } //解析的长度
public string BodyMD { set; get; }
}

public class questionSameInfo
{
public int _id { get; set; } //试题id
public double Same { get; set; } //相似度
public int Size { get; set; } //文本长度
}

假如 mongodb中的结构如上所示,已知一道题的_id和Samequestions 中的某一项的_id,想根据这两个id删除Samequestions中的某一项。

假如 试题的_id为sid,Samequestion中的某一项的_id为mid,可编写如下代码:

var helper = new MongoHelper2(conn,table);
var query=Query.EQ ("_id",sid);

var update=Update.Pull("Samequestions",Query.EQ("_id",mid));

var result = helper.UpdateOne(query, update);

posted @ 2015-01-13 21:03  jiang_jiang  阅读(548)  评论(0编辑  收藏  举报