4
我试图删除嵌入的文件没有成功。 我在寻找下一条指令Java的方式:MongoDB爪哇拉
db.games.update({'_id': 73}, {$pull: {'goals': {'goal': 4}}})
我试图删除嵌入的文件没有成功。 我在寻找下一条指令Java的方式:MongoDB爪哇拉
db.games.update({'_id': 73}, {$pull: {'goals': {'goal': 4}}})
Java文档是很清楚的,你只是构建BSON对象为在shell用于匹配各自的JSON同行:
BasicDBObject query = new BasicDBObject("_id", 73);
BasicDBObject fields = new BasicDBObject("goals",
new BasicDBObject("goal", 4));
BasicDBObject update = new BasicDBObject("$pull",fields);
games.update(query, update);
使用Bson是相似的。
Bson query = new Document().append("_id", 73);
Bson fields = new Document().append("goals", new Document().append("goal", 4));
Bson update = new Document("$pull",fields);
games.updateOne(query, update);
你想清除吗? $ unset是删除文档的命令。我假设你的意思是删除一个子文档。 – hellboy