public class MongoCollectionImpl extends AbstractMongoCollection
MongoCollection
interface.DELETE_SINGLE_DELETE_DEFAULT, EMPTY_INDEX_OPTIONS, INSERT_CONTINUE_ON_ERROR_DEFAULT, myClient, myDatabase, myName, UNIQUE_INDEX_OPTIONS, UPDATE_MULTIUPDATE_DEFAULT, UPDATE_UPSERT_DEFAULT
Constructor and Description |
---|
MongoCollectionImpl(Client client,
MongoDatabase database,
String name)
Create a new MongoDatabaseClient.
|
Modifier and Type | Method and Description |
---|---|
void |
aggregateAsync(Callback<List<Document>> results,
Aggregate command)
Invokes a aggregate command on the server.
|
void |
countAsync(Callback<Long> results,
DocumentAssignable query,
ReadPreference readPreference)
Counts the set of documents matching the query document in the
collection.
|
void |
createIndex(String name,
DocumentAssignable options,
Element... keys)
Creates an index with a generated name, across the keys specified
allowing duplicate entries.
|
void |
deleteAsync(Callback<Long> results,
DocumentAssignable query,
boolean singleDelete,
Durability durability)
Deletes a set of documents matching a query from the collection.
|
void |
distinctAsync(Callback<ArrayElement> results,
Distinct command)
Invokes a distinct command on the server.
|
boolean |
drop()
Drops the collection from the database.
|
boolean |
dropIndex(String name)
Deletes the indexes with the provided name.
|
void |
findAndModifyAsync(Callback<Document> results,
FindAndModify command)
Invokes a findAndModify command on the server.
|
void |
findAsync(Callback<ClosableIterator<Document>> results,
Find query)
Finds the set of documents matching the query in the collection.
|
void |
findOneAsync(Callback<Document> results,
DocumentAssignable query)
Finds a single matching document in the collection.
|
void |
groupByAsync(Callback<ArrayElement> results,
GroupBy command)
Invokes a group command on the server.
|
void |
insertAsync(Callback<Integer> results,
boolean continueOnError,
Durability durability,
DocumentAssignable... documents)
Inserts a set of documents into the collection.
|
void |
mapReduceAsync(Callback<List<Document>> results,
MapReduce command)
Invokes a mapReduce command on the server.
|
void |
updateAsync(Callback<Long> results,
DocumentAssignable query,
DocumentAssignable update,
boolean multiUpdate,
boolean upsert,
Durability durability)
Applies updates to a set of documents within the collection.
|
aggregate, aggregateAsync, asGetLastError, buildIndexName, count, count, countAsync, countAsync, countAsync, createIndex, createIndex, createIndex, createIndex, delete, delete, delete, delete, deleteAsync, deleteAsync, deleteAsync, deleteAsync, deleteAsync, deleteAsync, deleteAsync, distinct, distinctAsync, dropIndex, find, find, findAndModify, findAndModifyAsync, findAsync, findAsync, findAsync, findOne, findOneAsync, getDatabaseName, getDefaultDurability, getDefaultReadPreference, getName, groupBy, groupByAsync, insert, insert, insert, insert, insertAsync, insertAsync, insertAsync, insertAsync, insertAsync, insertAsync, insertAsync, mapReduce, mapReduceAsync, update, update, update, update, updateAsync, updateAsync, updateAsync, updateAsync, updateAsync, updateAsync, updateAsync
public MongoCollectionImpl(Client client, MongoDatabase database, String name)
client
- The client for interacting with MongoDB.database
- The database the collection is a part of.name
- The name of the collection we interact with.public void aggregateAsync(Callback<List<Document>> results, Aggregate command) throws MongoDbException
This is the canonical aggregate
method that implementations
must override.
Overridden to construct a aggregate command and send it to the server.
aggregateAsync
in interface MongoCollection
aggregateAsync
in class AbstractMongoCollection
results
- Callback for the aggregation results returned.command
- The details of the aggregation request.MongoDbException
- On an error executing the aggregate command.MongoCollection.aggregateAsync(Callback, Aggregate)
public void countAsync(Callback<Long> results, DocumentAssignable query, ReadPreference readPreference) throws MongoDbException
This is the canonical count
method that implementations must
override.
This is the canonical count
method that implementations must
override.
countAsync
in interface MongoCollection
countAsync
in class AbstractMongoCollection
results
- The callback to notify of the results.query
- The query document.readPreference
- The preference for which servers to use to retrieve the
results.MongoDbException
- On an error finding the documents.public void createIndex(String name, DocumentAssignable options, Element... keys) throws MongoDbException
This method is intended to be used with the
Sort
class's static methods:
import static
com.allanbank.mongodb.bson.builder.BuilderFactory.start
; import staticcom.allanbank.mongodb.builder.Sort.asc
; import staticcom.allanbank.mongodb.builder.Sort.desc
; MongoCollection collection = ...; collection.createIndex("sparse_f", start().add("sparse", true), asc("f") ); ...
This is the canonical createIndex
method that
implementations must override.
Overridden to insert the index document into the 'system.indexes' collection.
createIndex
in interface MongoCollection
createIndex
in class AbstractMongoCollection
name
- The name of the index. If null
then a name is
generated based on the keys.options
- The options for the index.keys
- The keys to use for the index.MongoDbException
- On a failure building the index.MongoCollection.createIndex(String,DocumentAssignable,Element...)
public void deleteAsync(Callback<Long> results, DocumentAssignable query, boolean singleDelete, Durability durability) throws MongoDbException
This is the canonical delete
method that implementations
must override.
Overridden to send a Delete
message to the server.
deleteAsync
in interface MongoCollection
deleteAsync
in class AbstractMongoCollection
results
- Callback that will be notified of the results of the query. If
the durability of the operation is NONE then this will be -1.query
- Query to locate the documents to be deleted.singleDelete
- If true then only a single document will be deleted. If
running in a sharded environment then this field must be false
or the query must contain the shard key.durability
- The durability for the delete.MongoDbException
- On an error deleting the documents.MongoCollection.deleteAsync(Callback, DocumentAssignable, boolean,
Durability)
public void distinctAsync(Callback<ArrayElement> results, Distinct command) throws MongoDbException
This is the canonical disitnct
method that implementations
must override.
Overridden to construct a 'distinct' command and send it to the server.
distinctAsync
in interface MongoCollection
distinctAsync
in class AbstractMongoCollection
results
- Callback for the distinct results returned.command
- The details of the distinct request.MongoDbException
- On an error finding the documents.public boolean drop()
Overridden to issue a { "drop" :
MongoCollection.drop()
public boolean dropIndex(String name) throws MongoDbException
This is the canonical dropIndex
method that implementations
must override.
Overridden to issue a { "deleteIndexes" :
dropIndex
in interface MongoCollection
dropIndex
in class AbstractMongoCollection
name
- The name of the index.MongoDbException
- On an error deleting the indexes.public void findAndModifyAsync(Callback<Document> results, FindAndModify command) throws MongoDbException
This is the canonical findAndModify
method that
implementations must override.
Overridden to send an Command
findAndModify message to the
server.
findAndModifyAsync
in interface MongoCollection
findAndModifyAsync
in class AbstractMongoCollection
results
- Callback for the the found document.command
- The details of the find and modify request.MongoDbException
- On an error finding the documents.MongoCollection.findAndModifyAsync(Callback, FindAndModify)
public void findAsync(Callback<ClosableIterator<Document>> results, Find query) throws MongoDbException
This is the canonical find
method that implementations must
override.
Overridden to send a Query
message to the server.
findAsync
in interface MongoCollection
findAsync
in class AbstractMongoCollection
results
- Callback that will be notified of the results of the query.query
- The query details.MongoDbException
- On an error finding the documents.MongoCollection.findAsync(Callback, Find)
public void findOneAsync(Callback<Document> results, DocumentAssignable query) throws MongoDbException
This is the canonical findOne
method that implementations
must override.
Overridden to send a Query
message to the server.
findOneAsync
in interface MongoCollection
findOneAsync
in class AbstractMongoCollection
results
- Callback that will be notified of the results of the query.query
- The query document.MongoDbException
- On an error finding the document.MongoCollection.findOneAsync(Callback, DocumentAssignable)
public void groupByAsync(Callback<ArrayElement> results, GroupBy command) throws MongoDbException
This is the canonical groupBy
method that implementations
must override.
Overridden to construct a group command and send it to the server.
groupByAsync
in interface MongoCollection
groupByAsync
in class AbstractMongoCollection
results
- Callback for the group results returned.command
- The details of the group request.MongoDbException
- On an error finding the documents.public void insertAsync(Callback<Integer> results, boolean continueOnError, Durability durability, DocumentAssignable... documents) throws MongoDbException
This is the canonical insert
method that implementations
must override.
Overridden to send an Insert
message to the server.
insertAsync
in interface MongoCollection
insertAsync
in class AbstractMongoCollection
results
- Callback
that will be notified with the results of the
insert. If the durability of the operation is NONE then this
will be -1.continueOnError
- If the insert should continue if one of the documents causes
an error.durability
- The durability for the insert.documents
- The documents to add to the collection.MongoDbException
- On an error inserting the documents.MongoCollection.insertAsync(Callback, boolean, Durability,
DocumentAssignable[])
public void mapReduceAsync(Callback<List<Document>> results, MapReduce command) throws MongoDbException
This is the canonical mapReduce
method that implementations
must override.
Overridden to construct a mapReduce command and send it to the server.
mapReduceAsync
in interface MongoCollection
mapReduceAsync
in class AbstractMongoCollection
results
- Callback for the map/reduce results returned. Note this might
be empty if the output type is not inline.command
- The details of the map/reduce request.MongoDbException
- On an error finding the documents.MongoCollection.mapReduceAsync(Callback, MapReduce)
public void updateAsync(Callback<Long> results, DocumentAssignable query, DocumentAssignable update, boolean multiUpdate, boolean upsert, Durability durability) throws MongoDbException
This is the canonical update
method that implementations
must override.
Overridden to send an Update
message to the server.
updateAsync
in interface MongoCollection
updateAsync
in class AbstractMongoCollection
results
- The Callback
that will be notified of the number of
documents updated. If the durability of the operation is NONE
then this will be -1.query
- The query to select the documents to update.update
- The updates to apply to the selected documents.multiUpdate
- If true then the update is applied to all of the matching
documents, otherwise only the first document found is updated.upsert
- If true then if no document is found then a new document is
created and updated, otherwise no operation is performed.durability
- The durability for the update.MongoDbException
- On an error updating the documents.MongoCollection.updateAsync(Callback, DocumentAssignable,
DocumentAssignable, boolean, boolean, Durability)
Copyright © 2011-2012 Allanbank Consulting, Inc.. All Rights Reserved.