diff --git a/src/main/java/org/springframework/datastore/document/mongodb/MongoTemplate.java b/src/main/java/org/springframework/datastore/document/mongodb/MongoTemplate.java index d91b01cb6..3a4eb1d00 100644 --- a/src/main/java/org/springframework/datastore/document/mongodb/MongoTemplate.java +++ b/src/main/java/org/springframework/datastore/document/mongodb/MongoTemplate.java @@ -51,23 +51,22 @@ public class MongoTemplate extends AbstractDocumentStoreTemplate { } public void execute(String command) { - CommandResult cr = getConnection().command(command); - String err = cr.getErrorMessage(); - if (err != null) { - throw new InvalidDataAccessApiUsageException("Command execution of " + - command + " failed: " + err); - } + execute((DBObject)JSON.parse(command)); } public void execute(DocumentSource command) { - CommandResult cr = getConnection().command(command.getDocument()); + execute(command.getDocument()); + } + + public void execute(DBObject command) { + CommandResult cr = getConnection().command(command); String err = cr.getErrorMessage(); if (err != null) { throw new InvalidDataAccessApiUsageException("Command execution of " + - command.getDocument().toString() + " failed: " + err); + command.toString() + " failed: " + err); } } - + public void createCollection(String collectionName, DocumentSource documentSource) { try { getConnection().createCollection(collectionName, documentSource.getDocument());