Announcement Announcement Module
Collapse
No announcement yet.
MongoDb multiple $pushAll Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • MongoDb multiple $pushAll

    Hi I'm trying to build an Update where I pushAll into two arrays in one statement. Can this be done?

    Code:
    db.foo.update({ id : "xxx" }, 
                       { $pushAll : { "people" : [{"name":"new person"}], 
                                           "friends" : [{"name":"new friend"}] } 
    } )

  • #2
    I fixed it but this should be supported by fwk. Or have I missed something?

    Code:
        private static class MultiPushUpdate extends Update {
            public MultiPushUpdate multiPushAll(String key, Object... values) {
                super.addMultiFieldOperation("$pushAll", key, values);
                return this;
            }
        }
    
        ....
        ....
        Query query = query(where("id").is("xxx"));
        Update update = new MultiPushUpdate()
                                       .multiPushAll("people", people)
                                       .multiPushAll("friends", friends);

    Comment

    Working...
    X