Fix MongoDB plugin update commands produce an empty response (#469)
This commit is contained in:
parent
7944ad535a
commit
3353962719
|
|
@ -118,8 +118,10 @@ public class MongoPlugin extends BasePlugin {
|
|||
// For the `findAndModify` command, we don't get the count of modifications made. Instead, we either
|
||||
// get the modified new value or the pre-modified old value (depending on the `new` field in the
|
||||
// command. Let's return that value to the user.
|
||||
if (mongoOutput.containsKey(VALUE_STR)) {
|
||||
result.setBody(new JSONObject().put(VALUE_STR, mongoOutput.get(VALUE_STR)));
|
||||
if (outputJson.has(VALUE_STR)) {
|
||||
result.setBody(objectMapper.readTree(
|
||||
cleanUp(new JSONObject().put(VALUE_STR, outputJson.get(VALUE_STR))).toString()
|
||||
));
|
||||
}
|
||||
|
||||
//The json contains key "cursor" when find command was issued and there are 1 or more results. In case
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import com.appsmith.external.models.DatasourceConfiguration;
|
|||
import com.appsmith.external.models.Endpoint;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mongodb.MongoClient;
|
||||
import com.mongodb.client.MongoCollection;
|
||||
import org.bson.Document;
|
||||
|
|
@ -38,6 +39,7 @@ public class MongoPluginTest {
|
|||
@ClassRule
|
||||
public static GenericContainer mongoContainer = new GenericContainer("mongo:4.2.0")
|
||||
.withExposedPorts(27017);
|
||||
private JsonNode value;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
|
|
@ -172,6 +174,11 @@ public class MongoPluginTest {
|
|||
assertNotNull(result);
|
||||
assertTrue(result.getIsExecutionSuccess());
|
||||
assertNotNull(result.getBody());
|
||||
value = ((ObjectNode) result.getBody()).get("value");
|
||||
assertNotNull(value);
|
||||
assertEquals("M", value.get("gender").asText());
|
||||
assertEquals("Alden Cantrell", value.get("name").asText());
|
||||
assertEquals(30, value.get("age").asInt());
|
||||
})
|
||||
.verifyComplete();
|
||||
}
|
||||
|
|
@ -200,8 +207,8 @@ public class MongoPluginTest {
|
|||
final JsonNode node = body.get(0);
|
||||
assertTrue(node.get("_id").isTextual());
|
||||
assertTrue(node.get("luckyNumber").isNumber());
|
||||
assertEquals(node.get("dob").asText(), "2018-12-31T00:00:00Z");
|
||||
assertEquals(node.get("netWorth").toString(), "123456.789012");
|
||||
assertEquals("2018-12-31T00:00:00Z", node.get("dob").asText());
|
||||
assertEquals("123456.789012", node.get("netWorth").toString());
|
||||
})
|
||||
.verifyComplete();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user