hehe hehe -5 years ago 313
Java Question

MongoDB Java pull

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

Answer Source

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 );
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download