本文介绍了MongoDB Java拉的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试删除嵌入式文档但没有成功。
我正在寻找以下指令的java方式:

i tried to remove an embedded document without succcess.I'm looking for the java way of following instruction:

db.games.update({'_id': 73}, {$pull: {'goals': {'goal': 4}}})


推荐答案

Java文档很清楚,你只是在构建BSON对象以匹配shell中使用的各自的JSON对应物:

The Java documentation is pretty clear, you are just constructing BSON objects to match their respective JSON counterparts as used in the shell:

    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 );

这篇关于MongoDB Java拉的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-14 04:50