Executing Commands

You can get at the MongoDB driver’s MongoDatabase.runCommand( ) method by using the executeCommand(…) methods on MongoTemplate. These methods also perform exception translation into Spring’s DataAccessException hierarchy.

Methods for executing commands

  • Document executeCommand (Document command): Run a MongoDB command.

  • Document executeCommand (Document command, ReadPreference readPreference): Run a MongoDB command with the given nullable MongoDB ReadPreference.

  • Document executeCommand (String jsonCommand): Execute a MongoDB command expressed as a JSON string.