File tree 2 files changed +38
-3
lines changed
main/java/org/springframework/data/mongodb/core/query
test/java/org/springframework/data/mongodb/core/query
2 files changed +38
-3
lines changed Original file line number Diff line number Diff line change 31
31
* @author Thomas Risberg
32
32
* @author Mark Pollack
33
33
* @author Oliver Gierke
34
+ * @author Becca Gaspard
34
35
*/
35
36
public class Update {
36
37
@@ -90,6 +91,18 @@ public Update set(String key, Object value) {
90
91
return this ;
91
92
}
92
93
94
+ /**
95
+ * Update using the $setOnInsert update modifier
96
+ *
97
+ * @param key
98
+ * @param value
99
+ * @return
100
+ */
101
+ public Update setOnInsert (String key , Object value ) {
102
+ addMultiFieldOperation ("$setOnInsert" , key , value );
103
+ return this ;
104
+ }
105
+
93
106
/**
94
107
* Update using the $unset update modifier
95
108
*
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2010-2011 the original author or authors.
2
+ * Copyright 2010-2013 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
20
20
21
21
import org .junit .Assert ;
22
22
import org .junit .Test ;
23
- import org .springframework .data .mongodb .core .query .BasicUpdate ;
24
- import org .springframework .data .mongodb .core .query .Update ;
25
23
24
+ /**
25
+ * Test cases for {@link Update}.
26
+ *
27
+ * @author Oliver Gierke
28
+ * @author Becca Gaspard
29
+ */
26
30
public class UpdateTests {
27
31
28
32
@ Test
@@ -135,4 +139,22 @@ public void testBasicUpdateIncAndSet() {
135
139
Assert .assertEquals ("{ \" $inc\" : { \" size\" : 1} , \" $set\" : { \" directory\" : \" /Users/Test/Desktop\" }}" , u
136
140
.getUpdateObject ().toString ());
137
141
}
142
+
143
+ /**
144
+ * @see DATAMONGO-630
145
+ */
146
+ @ Test
147
+ public void testSetOnInsert () {
148
+ Update u = new Update ().setOnInsert ("size" , 1 );
149
+ Assert .assertEquals ("{ \" $setOnInsert\" : { \" size\" : 1}}" , u .getUpdateObject ().toString ());
150
+ }
151
+
152
+ /**
153
+ * @see DATAMONGO-630
154
+ */
155
+ @ Test
156
+ public void testSetOnInsertSetOnInsert () {
157
+ Update u = new Update ().setOnInsert ("size" , 1 ).setOnInsert ("count" , 1 );
158
+ Assert .assertEquals ("{ \" $setOnInsert\" : { \" size\" : 1 , \" count\" : 1}}" , u .getUpdateObject ().toString ());
159
+ }
138
160
}
You can’t perform that action at this time.
0 commit comments