我有一个包含元素的集合会话
{
"_id" : NumberLong(1),
"_class" : "cws.CWSession",
"title" : "java ",
"description" : "apprendre à programmer en java"
}
{
"_id" : NumberLong(2),
"_class" : "cws.CWSession",
"title" : "Git",
"description" : "Formation Git"
}
我还有另一个包含 CWSession 的 dbRed 的集合:
{
"_id" : NumberLong(2),
"_class" : "cws.CollaborativeWs",
"title" : "AngularJS",
"description" : "AngularJS",
"cws" : [
{
"$ref" : "cwsession",
"$id" : NumberLong(1)
},
{
"$ref" : "cwsession",
"$id" : NumberLong(2)
}
]
}
{
"_id" : NumberLong(3),
"_class" : "cws.CollaborativeWs",
"title" : "Java",
"description" : "principes java ",
"cws" : [
{
"$ref" : "cwsession",
"$id" : NumberLong(3)
}
]
}
我使用 mongo 模板删除会话
mongoTemplate.remove(new Query(Criteria.where("_id").is(id)), CWSession.class);
它工作正常,会话在第一个集合中被删除,但仍然在第二个集合中,你能告诉我我可以用什么来删除第二个集合中的引用吗?并提前感谢您。
public void deleteSessionfromCW(String idCW, String idS){
Query query = new Query(where("_id").is(idCW).and("cws.id").is(id));
Update update = new Update().pull("cws", new BasicDBObject("id", "1"));
mongoTemplate.updateFirst(query, update, Item.class);
}