diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/CollectionOptions.java b/spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/CollectionOptions.java
index 3c884ae32..eb6fb7d15 100644
--- a/spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/CollectionOptions.java
+++ b/spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/CollectionOptions.java
@@ -15,6 +15,12 @@
*/
package org.springframework.data.document.mongodb;
+/**
+ * Provides a simple wrapper to encapsulate the variety of settings you can use when creating a collection.
+ *
+ * @author Thomas Risberg
+ *
+ */
public class CollectionOptions {
private Integer maxDocuments;
@@ -23,8 +29,13 @@ public class CollectionOptions {
private Boolean capped;
-
-
+ /**
+ * Constructs a new CollectionOptions instance.
+ * @param size the collection size in bytes, this data space is preallocated
+ * @param maxDocuments the maximum number of documents in the collection.
+ * @param capped true to created a "capped" collection (fixed size with auto-FIFO behavior
+ * based on insertion order), false otherwise.
+ */
public CollectionOptions(Integer size, Integer maxDocuments, Boolean capped) {
super();
this.maxDocuments = maxDocuments;
diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/MongoOperations.java b/spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/MongoOperations.java
index ac6f8208a..9d6167929 100644
--- a/spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/MongoOperations.java
+++ b/spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/MongoOperations.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2010 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.springframework.data.document.mongodb;
import java.util.List;
@@ -5,100 +20,371 @@ import java.util.List;
import com.mongodb.DBCollection;
import com.mongodb.DBObject;
+/**
+ * Interface that specifies a basic set of MongoDB operations. Implemented by {@link MongoTemplate}.
+ * Not often used but a useful option for extensibility and testability (as it can be easily mocked, stubbed, or be
+ * the target of a JDK proxy).
+ *
+ * @author Thomas Risberg
+ * @author Mark Pollack
+ *
+ */
public interface MongoOperations {
+ /**
+ * The default collection name used by this template.
+ * @return
+ */
String getDefaultCollectionName();
/**
+ * The default collection used by this template
* @return The default collection used by this template
*/
DBCollection getDefaultCollection();
+
+ /**
+ * Execute the a MongoDB command expressed as a JSON string. This will call the method
+ * JSON.parse that is part of the MongoDB driver to convert the JSON string to a DBObject.
+ * Any errors that result from executing this command will be converted into Spring's DAO
+ * exception hierarchy.
+ * @param jsonCommand a MongoDB command expressed as a JSON string.
+ */
void executeCommand(String jsonCommand);
+ /**
+ * Execute a MongoDB command. Any errors that result from executing this command will be converted
+ * into Spring's DAO exception hierarchy.
+ * @param command a MongoDB command
+ */
void executeCommand(DBObject command);
/**
- * Executes a {@link DBCallback} translating any exceptions as necessary
+ * Executes a {@link DBCallback} translating any exceptions as necessary.
*
- * @param The return type
- * @param action The action to execute
+ * Allows for returning a result object, that is a domain object or a collection of domain objects.
*
- * @return The return value of the {@link DBCallback}
+ * @param return type
+ * @param action callback object that specifies the MongoDB actions to perform on the passed in DB instance.
+ *
+ * @return a result object returned by the action or null
*/
T execute(DBCallback action);
/**
* Executes the given {@link CollectionCallback} on the default collection.
*
- * @param
- * @param callback
- * @return
+ * Allows for returning a result object, that is a domain object or a collection of domain objects.
+ *
+ * @param return type
+ * @param action callback object that specifies the MongoDB action
+ * @return a result object returned by the action or null
*/
- T execute(CollectionCallback callback);
+ T execute(CollectionCallback action);
/**
* Executes the given {@link CollectionCallback} on the collection of the given name.
*
- * @param
- * @param callback
- * @param collectionName
- * @return
+ * Allows for returning a result object, that is a domain object or a collection of domain objects.
+ *
+ * @param return type
+ * @param action callback object that specifies the MongoDB action
+ * @param collectionName the name of the collection that specifies which DBCollection instance will be passed into
+ * the callback action.
+ * @return a result object returned by the action or null
*/
- T execute(CollectionCallback callback, String collectionName);
+ T execute(CollectionCallback action, String collectionName);
+ /**
+ * Executes the given {@link DBCallback} within the same connection to the database so as to ensure
+ * consistency in a write heavy environment where you may read the data that you wrote. See the
+ * comments on {@see Java Driver Concurrency}
+ *
+ * Allows for returning a result object, that is a domain object or a collection of domain objects.
+ *
+ * @param return type
+ * @param action callback that specified the MongoDB actions to perform on the DB instance
+ * @return a result object returned by the action or null
+ */
T executeInSession(DBCallback action);
+ /**
+ * Create an uncapped collection with the provided name.
+ * @param collectionName name of the collection
+ * @return the created collection
+ */
DBCollection createCollection(String collectionName);
- void createCollection(String collectionName,
- CollectionOptions collectionOptions);
+ /**
+ * Create a collect with the provided name and options
+ * @param collectionName name of the collection
+ * @param collectionOptions options to use when creating the collection.
+ */
+ void createCollection(String collectionName, CollectionOptions collectionOptions);
+ /**
+ * A list of collection names
+ * @return list of collection names
+ */
List getCollectionNames();
+ /**
+ * Get a collection by name, creating it if it doesn't exist.
+ *
+ * Translate any exceptions as necessary.
+ *
+ * @param collectionName name of the collection
+ * @return an existing collection or a newly created one.
+ */
DBCollection getCollection(String collectionName);
+ /**
+ * Check to see if a collection with a given name exists.
+ *
+ * Translate any exceptions as necessary.
+ *
+ * @param collectionName name of the collection
+ * @return true if a collection with the given name is found, false otherwise.
+ */
boolean collectionExists(String collectionName);
+ /**
+ * Drop the collection with the given name.
+ *
+ * Translate any exceptions as necessary.
+ *
+ * @param collectionName name of the collection to drop/delete.
+ */
void dropCollection(String collectionName);
+ /**
+ * Insert the object into the default collection.
+ *
+ * The object is converted to the MongoDB native representation using an instance of
+ * {@see MongoConverter}. Unless configured otherwise, an
+ * instance of SimpleMongoConverter will be used.
+ *
+ * If you object has an "Id' property, it will be set with the generated Id from MongoDB. If your Id property
+ * is a String then MongoDB ObjectId will be used to populate that string. Otherwise, the conversion from
+ * ObjectId to your property type will be handled by Spring's BeanWrapper class that leverages Spring 3.0's
+ * new Type Conversion API.
+ * See Spring 3 Type Conversion"
+ * for more details.
+ *
+ *
+ * Insert is used to initially store the object into the database.
+ * To update an existing object use the save method.
+ *
+ * @param objectToSave the object to store in the collection.
+ */
void insert(Object objectToSave);
+ /**
+ * Insert the object into the specified collection.
+ *
+ * The object is converted to the MongoDB native representation using an instance of
+ * {@see MongoConverter}. Unless configured otherwise, an
+ * instance of SimpleMongoConverter will be used.
+ *
+ * Insert is used to initially store the object into the
+ * database. To update an existing object use the save method.
+ *
+ * @param collectionName name of the collection to store the object in
+ * @param objectToSave the object to store in the collection
+ */
void insert(String collectionName, Object objectToSave);
+ /**
+ * Insert the object into the specified collection.
+ *
+ * The object is converted to the MongoDB native representation using an instance of
+ * {@see MongoWriter}
+ *
+ * Insert is used to initially store the object into the
+ * database. To update an existing object use the save method.
+ *
+ * @param the type of the object to insert
+ * @param collectionName name of the collection to store the object in
+ * @param objectToSave the object to store in the collection
+ * @param writer the writer to convert the object to save into a DBObject
+ */
void insert(String collectionName, T objectToSave, MongoWriter writer);
+ /**
+ * Insert a list of objects into the default collection in a single batch write to the database.
+ *
+ * @param listToSave the list of objects to save.
+ */
void insertList(List