DATAMONGO-630 - Support $setOnInsert update operator.
Original pull request: #70.
This commit is contained in:
committed by
Oliver Gierke
parent
fb979b1734
commit
eebd49ab8d
@@ -31,6 +31,7 @@ import com.mongodb.DBObject;
|
||||
* @author Thomas Risberg
|
||||
* @author Mark Pollack
|
||||
* @author Oliver Gierke
|
||||
* @author Becca Gaspard
|
||||
*/
|
||||
public class Update {
|
||||
|
||||
@@ -90,6 +91,18 @@ public class Update {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update using the $setOnInsert update modifier
|
||||
*
|
||||
* @param key
|
||||
* @param value
|
||||
* @return
|
||||
*/
|
||||
public Update setOnInsert(String key, Object value) {
|
||||
addMultiFieldOperation("$setOnInsert", key, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update using the $unset update modifier
|
||||
*
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2011 the original author or authors.
|
||||
* Copyright 2010-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -20,9 +20,13 @@ import java.util.Map;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.mongodb.core.query.BasicUpdate;
|
||||
import org.springframework.data.mongodb.core.query.Update;
|
||||
|
||||
/**
|
||||
* Test cases for {@link Update}.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Becca Gaspard
|
||||
*/
|
||||
public class UpdateTests {
|
||||
|
||||
@Test
|
||||
@@ -135,4 +139,22 @@ public class UpdateTests {
|
||||
Assert.assertEquals("{ \"$inc\" : { \"size\" : 1} , \"$set\" : { \"directory\" : \"/Users/Test/Desktop\"}}", u
|
||||
.getUpdateObject().toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAMONGO-630
|
||||
*/
|
||||
@Test
|
||||
public void testSetOnInsert() {
|
||||
Update u = new Update().setOnInsert("size", 1);
|
||||
Assert.assertEquals("{ \"$setOnInsert\" : { \"size\" : 1}}", u.getUpdateObject().toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAMONGO-630
|
||||
*/
|
||||
@Test
|
||||
public void testSetOnInsertSetOnInsert() {
|
||||
Update u = new Update().setOnInsert("size", 1).setOnInsert("count", 1);
|
||||
Assert.assertEquals("{ \"$setOnInsert\" : { \"size\" : 1 , \"count\" : 1}}", u.getUpdateObject().toString());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user