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 7bd096c94..1482d3ad3 100644 --- a/src/main/java/org/springframework/datastore/document/mongodb/MongoTemplate.java +++ b/src/main/java/org/springframework/datastore/document/mongodb/MongoTemplate.java @@ -58,12 +58,25 @@ public class MongoTemplate extends AbstractDocumentStoreTemplate { return connectionFactory; } + public void execute(String command) { + DB db = getDocumentStoreConnectionFactory().getConnection(); + CommandResult cr = db.command(command); + String err = cr.getErrorMessage(); + if (err != null) { + throw new InvalidDataAccessApiUsageException("Command execution of " + + command + " failed: " + err); + } + } public void execute(DocumentSource command) { CommandResult cr = getDocumentStoreConnectionFactory() .getConnection() .command(command.getDocument()); - System.out.println("! " + cr.getErrorMessage()); + String err = cr.getErrorMessage(); + if (err != null) { + throw new InvalidDataAccessApiUsageException("Command execution of " + + command.getDocument().toString() + " failed: " + err); + } } public void createCollection(String collectionName, DocumentSource documentSource) {