Results 1 to 2 of 2

Thread: MongoDb multiple $pushAll

  1. #1
    Join Date
    Aug 2011
    Posts
    3

    Default 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. #2
    Join Date
    Aug 2011
    Posts
    3

    Default

    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);

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •