spring 3 - Is the MongoDB $push operator the way to add an embedded document? -
i'm using mongodb , spring 3. have following domain object:
@document(collection = "users") public class user { @id private string id; private list<post> posts; } i want add post user, best/most efficient way that? can see way programmatically - find user, add new post object list , save user again - don't think elegant or efficient.
from documentation seems need use $push operator can't seem find examples of how spring's mongotemplate. can provide example?
$push correct way add new document array.
you can see example code in this presentation (slide 22). relevant line be:
mongotemplate.updatefirst(collection, ... new query(where("_id").is(...)), ... new update().push("field", dbo));
Comments
Post a Comment