如何更新所有数组形成一个集合mongodb

时间:2018-07-19 18:34:56

标签: java arrays mongodb

我正在使用Java与mongo连接,所以我有一个这样的集合:

//collection
{
   "_id" : ObjectId("5b50d0bf84c9832748a94f41"),
   "arrayA" : ["a","b","c"],
   "arrayB" : ["d","e","f"],
   "arrayC" : ["g","h","i"],
   "arrayD" : ["j","k","l"],
   "another_vale" : "hello"
}

当我必须进行更新时,我会执行以下操作:

 collection.updateOne(new Document("_id",doc.get("_id")), new Document("$push", new Document("arrayA", "some new value")));
 collection.updateOne(new Document("_id",doc.get("_id")), new Document("$push", new Document("arrayB", "some new value")));
 collection.updateOne(new Document("_id",doc.get("_id")), new Document("$push", new Document("arrayC", "some new value")));
 collection.updateOne(new Document("_id",doc.get("_id")), new Document("$push", new Document("arrayD", "some new value")));

它有效,但是我的问题是: 有没有办法在一行上完成所有这些工作? ,我是说一个

 collection.updateOne(/*something*/)

0 个答案:

没有答案