new BasicDBObject().append("$push", dbBasicListOfCars);
In the above statement, you are trying to insert a key-value pair in DBObject with key as "$push" and value as dbBasicListOfCars.
MongoDB doesnt allow key to have a '$' hence it is failing.
However, the way you are trying to save is also wrong.
What you need is com.mongodb.BasicDBList, which is a utility class to allow array DBObjects to be created.
BasicDBList only supports numeric keys. Passing strings that cannot be converted to ints will cause an IllegalArgumentException.
BasicDBList list = new BasicDBList();
list.put("1", "bar"); // ok
list.put("1E1", "bar"); // throws exception
refer : http://api.mongodb.org/java/current/com/mongodb/BasicDBList.html
Note: MongoDB will also create arrays from java.util.Lists.
DBObject obj = new BasicDBList();
obj.put( "0", value1 );
obj.put( "4", value2 );
obj.put( 2, value3 );
This simulates the array [ value1, null, value3, null, value2 ] by creating the DBObject { "0" : value1, "1" : null, "2" : value3, "3" : null, "4" : value2 }.
saveandupdatemethods in MongoDB.$pushoperation is forupdatemethod.