How to add/remove elements from a MongoDB list using spring data? -


i using spring data talk mongo (although know there few downsides on mongo driver advanced use cases). application has mongodb document 1 of elements being list. want add/delete specific elements list in document. can please tell me if , how spring data supports (considering basic operation)?

i did quite web search didn't seem land on concrete.

any appreciable.

update 1: sample document:

{ id: 123, arr: [ 1,2,3,4]} 

and after update

{ id: 123, arr: [ 1,2,3]} or { id: 123, arr: [ 1,2,3,4,5]}

i'm looking @ unit tests , looks can use mongo $pull , $push methods using update class.

https://github.com/spring-projects/spring-data-mongodb/blob/master/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/query/updatetests.java

you can see tutorial here:

http://www.dineshonjava.com/2013/01/spring-data-mongodb-update-document.html#.vvexp3uvhbc

so you'd doing like:

update().pull("arr", 4); update().push("arr", 5); 

Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -