The Java drivver along with the python is the most developed one, so you can check it in the driver DOCS. Usually the idea (structure of the commands) is the same as in the shell you just need helpers to construct the command.
In Java this documentation can make some hints about how it works:DOCS
so for
$push:
Mongoshell DOCS example:
db.students.update(
{ name: "joe" },
{ $push: { scores: 89 } }
)
Where { name: "joe" } is a query identifing the right document to update and the scores is an array field and 89 will be abbended.
Java DOCS
example: check out this question : (MongoDB Java) $push into array
$elemmatch:
Mongoshell DOCS
example: check out this question:Convert MongoDB query into Java
$slice:
Mongoshell DOCS
syntax:
db.collection.update( <query>,
{ $push: {
<field>: {
$each: [ <value1>, <value2>, ... ],
$slice: <num>
}
}
}
)
In Java something like (Just cause i have not find for this exact update uitilized slice an example in java this is constructed by myself):
final MongoClient mongoClient = new MongoClient();
final DBCollection coll = mongoClient.getDB("TheDatabase").getCollection("TheCollection");
coll.update(<query>, new BasicDBObject("$push",
new BasicDBObject(<field>,
new BasicDBObject("$each",
new BasicDBList()
.put(0,<value1>)
.put(1,<value2>)
.put(3,<value3>))
.append('$slice',-5)));
example: check out these questions too for usage of slice in other cases: $slice mongoDB Java , Mongo java driver - retrieve slice of array without any other field or this thread :https://groups.google.com/forum/#!topic/mongodb-user/4c3P0_FOzyM