In the shell, you could do this using a command like:
db.XX.update(
// Find the document where userEmail=some@some.com and find the element in the "reservations" array where idRest=24
{
"userEmail":"some@some.com",
"reservations.idRest":24
},
// Update the element matched by the find criteria with new values
{
$set:{
"reservations.$.idRest":99,
"reservations.$.userPhone":"888888",
"reservations.$.date":"03-13-2015",
"reservations.$.hour":"17:30"
}
}
)
And the Java equivalent will look like:
...
DBObject selectQuery = new BasicDBObject("userEmail", rest.getEmailUser());
selectQuery.append("reservations.idRest", rest.getId());
BasicDBObject updateFields = new BasicDBObject();
updateFields.put("reservations.$.idRest", rest.getEmailUser());
updateFields.put("reservations.$.userPhone", rest.getPhoneUser());
updateFields.put("reservations.$.date", rest.getFecha());
updateFields.put("reservations.$.hour", rest.getHora());;
DBObject updateQuery = new BasicDBObject();
updateQuery.put("$set", updateFields);
collReservationByUser.update(selectQuery, updateQuery, true, true);
...
Note: If the "reservations" array has multiple elements with "idRest"=24, then the above query will only update the first matched element. It's not possible to update multiple elements within an array using positional operator.