を使用してアレイ:更新私はのようなJSONを持っているのMongoDB
{ "_id" : "1", "_class" : "com.model.Test", "itemList" : [ { "itemID" : "1", "itemName" : "Foo", "resources" : [ { "resourceID" : "1", "resourceName" : "Foo Test1", }, { "resourceID" : "2", "resourceName" : "Foo Test2", } ] } ] }
私は、リソースのリストを更新できるようにする必要があります。 私は次のことを行っている:
BasicDBObject updateQuery = new BasicDBObject();
updateQuery.put("id", "1");
BasicDBObject updateCommand = new BasicDBObject();
List<Resource> resources = populateResources();//Fetch a new list of Resources
updateCommand.put("$push", new BasicDBObject("resources", resources));
MongoOperations mongoOperations = mongoConfiguration.getMongoTemplate();
DBCollection db = mongoOperations.getCollection("myCollection");
db.save(updateCommand);
私はfollwoingエラーを取得する:私が使用した場合
java.lang.IllegalArgumentException: fields stored in the db can't start with '$' (Bad Key: '$push')
は:
:java.lang.IllegalArgumentException: can't serialize class com.model.Test
db.update(updateQuery, updateCommand, true, true);
を私は次の例外を得ました
私は試みました: db.updateMulti(updateQuery、updateCommand); 私は例外を何も得ておらず、更新はドキュメントに反映されませんでした。
ここで私は何が欠けているのですか?
ありがとうございました。非常に役に立ちました。 – Echo