public class SynchronousMongoCollectionImpl extends AbstractAsyncMongoCollection implements MongoCollection
MongoCollection
interface including the
synchronous methods.MongoCollection.ValidateMode
DELETE_SINGLE_DELETE_DEFAULT, EMPTY_INDEX_OPTIONS, ID_FIELD_NAME, INSERT_CONTINUE_ON_ERROR_DEFAULT, myClient, myDatabase, myName, UNIQUE_INDEX_OPTIONS, UPDATE_MULTIUPDATE_DEFAULT, UPDATE_UPSERT_DEFAULT
ALL, NONE
Constructor and Description |
---|
SynchronousMongoCollectionImpl(Client client,
MongoDatabase database,
String name)
Create a new MongoDatabaseClient.
|
Modifier and Type | Method and Description |
---|---|
protected void |
addOptions(String command,
DocumentAssignable options,
DocumentBuilder builder)
Adds the options to the document builder.
|
MongoIterator<Document> |
aggregate(Aggregate.Builder command)
Invokes a aggregate command on the server.
|
MongoIterator<Document> |
aggregate(Aggregate command)
Invokes a aggregate command on the server.
|
long |
count()
Counts the set of documents in the collection.
|
long |
count(Count.Builder count)
Counts the set of documents matching the query document in the
collection.
|
long |
count(Count count)
Counts the set of documents matching the query document in the
collection.
|
long |
count(DocumentAssignable query)
Counts the set of documents matching the query document in the
collection.
|
long |
count(DocumentAssignable query,
ReadPreference readPreference)
Counts the set of documents matching the query document in the
collection.
|
long |
count(ReadPreference readPreference)
Counts the set of documents in the collection.
|
void |
createIndex(boolean unique,
Element... keys)
Creates an index with a generated name, across the keys specified and if
unique is true ensuring entries are unique.
|
void |
createIndex(DocumentAssignable options,
Element... keys)
Creates an index with a generated name, across the keys specified
allowing duplicate entries.
|
void |
createIndex(Element... keys)
Creates an index with a generated name, across the keys specified
allowing duplicate entries.
|
void |
createIndex(String name,
boolean unique,
Element... keys)
Creates an index with the specified name, across the keys specified and
if unique is true ensuring entries are unique.
|
void |
createIndex(String name,
DocumentAssignable options,
Element... keys)
Creates an index with a generated name, across the keys specified
allowing duplicate entries.
|
long |
delete(DocumentAssignable query)
Deletes a set of documents matching a query from the collection.
|
long |
delete(DocumentAssignable query,
boolean singleDelete)
Deletes a set of documents matching a query from the collection.
|
long |
delete(DocumentAssignable query,
boolean singleDelete,
Durability durability)
Deletes a set of documents matching a query from the collection.
|
long |
delete(DocumentAssignable query,
Durability durability)
Deletes a set of documents matching a query from the collection.
|
protected Version |
determineIndexServerVersion(Element[] keys)
Determines the minimum server version required to support the provided
index keys and options.
|
MongoIterator<Element> |
distinct(Distinct.Builder command)
Invokes a distinct command on the server.
|
MongoIterator<Element> |
distinct(Distinct command)
Invokes a distinct command on the server.
|
boolean |
drop()
Drops the collection from the database.
|
boolean |
dropIndex(IntegerElement... keys)
Deletes the indexes matching the keys specified.
|
boolean |
dropIndex(String name)
Deletes the indexes with the provided name.
|
boolean |
exists()
Returns true if this collection already exists on the server.
|
Document |
explain(Aggregate.Builder aggregation)
Explains the way that the aggregation will be performed.
|
Document |
explain(Aggregate aggregation)
Explains the way that the aggregation will be performed.
|
Document |
explain(DocumentAssignable query)
Explains the way that the query will be performed.
|
Document |
explain(Find.Builder query)
Explains the way that the query will be performed.
|
Document |
explain(Find query)
Explains the way that the query will be performed.
|
MongoIterator<Document> |
find(DocumentAssignable query)
Finds the set of documents matching the query document in the collection.
|
MongoIterator<Document> |
find(Find.Builder query)
Finds the set of documents matching the query in the collection.
|
MongoIterator<Document> |
find(Find query)
Finds the set of documents matching the query in the collection.
|
Document |
findAndModify(FindAndModify.Builder command)
Invokes a findAndModify command on the server.
|
Document |
findAndModify(FindAndModify command)
Invokes a findAndModify command on the server.
|
Document |
findOne(DocumentAssignable query)
Finds a single matching document in the collection.
|
Document |
findOne(Find.Builder query)
Finds a single matching document in the collection.
|
Document |
findOne(Find query)
Overridden to call the
AbstractMongoOperations.findOneAsync(com.allanbank.mongodb.Callback, Find) . |
MongoIterator<Element> |
groupBy(GroupBy.Builder command)
Invokes a group command on the server.
|
MongoIterator<Element> |
groupBy(GroupBy command)
Invokes a group command on the server.
|
int |
insert(boolean continueOnError,
DocumentAssignable... documents)
Inserts a set of documents into the collection.
|
int |
insert(boolean continueOnError,
Durability durability,
DocumentAssignable... documents)
Inserts a set of documents into the collection.
|
int |
insert(DocumentAssignable... documents)
Inserts a set of documents into the collection.
|
int |
insert(Durability durability,
DocumentAssignable... documents)
Inserts a set of documents into the collection.
|
boolean |
isCapped()
Returns true if the collection
statistics indicate that
the collection is a capped collection. |
protected boolean |
isCreateIndexesSupported()
Determines if all of the servers in the cluster support the
createIndexes command. |
MongoIterator<Document> |
mapReduce(MapReduce.Builder command)
Invokes a mapReduce command on the server.
|
MongoIterator<Document> |
mapReduce(MapReduce command)
Invokes a mapReduce command on the server.
|
Collection<MongoIterator<Document>> |
parallelScan(ParallelScan.Builder parallelScan)
Uses the
parallelCollectionScan command to open multiple
iterators over the collection each configured to scan a distinct regions
of the collection. |
Collection<MongoIterator<Document>> |
parallelScan(ParallelScan parallelScan)
Uses the
parallelCollectionScan command to open multiple
iterators over the collection each configured to scan a distinct regions
of the collection. |
int |
save(DocumentAssignable document)
Saves the
document to the collection. |
int |
save(DocumentAssignable document,
Durability durability)
Saves the
document to the collection. |
BatchedAsyncMongoCollection |
startBatch()
Starts a batch of requests to the server.
|
Document |
stats()
Returns the statistics for the collection.
|
MongoIterator<TextResult> |
textSearch(Text.Builder command)
Deprecated.
Support for the
text command was deprecated in the
2.6 version of MongoDB. Use the
$text query operator
instead. This method will not be removed until two releases
after the MongoDB 2.6 release (e.g. 2.10 if the releases are
2.8 and 2.10). |
MongoIterator<TextResult> |
textSearch(Text command)
Deprecated.
Support for the
text command was deprecated in the
2.6 version of MongoDB. Use the
$text query operator
instead. This method will not be removed until two releases
after the MongoDB 2.6 release (e.g. 2.10 if the releases are
2.8 and 2.10). |
long |
update(DocumentAssignable query,
DocumentAssignable update)
Applies updates to a set of documents within the collection.
|
long |
update(DocumentAssignable query,
DocumentAssignable update,
boolean multiUpdate,
boolean upsert)
Applies updates to a set of documents within the collection.
|
long |
update(DocumentAssignable query,
DocumentAssignable update,
boolean multiUpdate,
boolean upsert,
Durability durability)
Applies updates to a set of documents within the collection.
|
long |
update(DocumentAssignable query,
DocumentAssignable update,
Durability durability)
Applies updates to a set of documents within the collection.
|
Document |
updateOptions(DocumentAssignable options)
Updates the collection's options or flags using the
collMod
command. |
Document |
validate(MongoCollection.ValidateMode mode)
Validates the collections contents.
|
long |
write(BatchedWrite.Builder write)
Constructs the appropriate set of write commands to send to the server.
|
long |
write(BatchedWrite write)
Constructs the appropriate set of write commands to send to the server.
|
aggregateAsync, aggregateAsync, aggregateAsync, aggregateAsync, aggregateAsync, countAsync, countAsync, countAsync, countAsync, countAsync, countAsync, countAsync, countAsync, countAsync, countAsync, countAsync, countAsync, countAsync, countAsync, countAsync, countAsync, countAsync, deleteAsync, deleteAsync, deleteAsync, deleteAsync, deleteAsync, deleteAsync, deleteAsync, deleteAsync, deleteAsync, deleteAsync, deleteAsync, distinctAsync, distinctAsync, distinctAsync, distinctAsync, distinctAsync, explainAsync, explainAsync, explainAsync, explainAsync, explainAsync, explainAsync, explainAsync, explainAsync, explainAsync, explainAsync, findAndModifyAsync, findAndModifyAsync, findAndModifyAsync, findAndModifyAsync, findAndModifyAsync, findAsync, findAsync, findAsync, findAsync, findAsync, findAsync, findAsync, findAsync, findOneAsync, findOneAsync, findOneAsync, findOneAsync, findOneAsync, findOneAsync, findOneAsync, findOneAsync, getLockType, groupByAsync, groupByAsync, groupByAsync, groupByAsync, groupByAsync, insertAsync, insertAsync, insertAsync, insertAsync, insertAsync, insertAsync, insertAsync, insertAsync, insertAsync, insertAsync, insertAsync, mapReduceAsync, mapReduceAsync, mapReduceAsync, mapReduceAsync, mapReduceAsync, parallelScanAsync, parallelScanAsync, parallelScanAsync, parallelScanAsync, parallelScanAsync, saveAsync, saveAsync, saveAsync, saveAsync, saveAsync, stream, stream, stream, stream, stream, stream, streamingFind, streamingFind, streamingFind, streamingFind, streamingFind, streamingFind, textSearchAsync, textSearchAsync, textSearchAsync, updateAsync, updateAsync, updateAsync, updateAsync, updateAsync, updateAsync, updateAsync, updateAsync, updateAsync, updateAsync, updateAsync, writeAsync, writeAsync, writeAsync, writeAsync, writeAsync
aggregateAsync, asGetLastError, countAsync, createQuery, deleteAsync, distinctAsync, doInsertAsync, doWriteAsync, explainAsync, explainAsync, findAndModifyAsync, findAsync, findOneAsync, getDatabaseName, getDurability, getName, getReadPreference, groupByAsync, insertAsync, isWriteCommandsSupported, mapReduceAsync, parallelScanAsync, saveAsync, setDurability, setReadPreference, stream, stream, textSearchAsync, toCommand, updateAsync, updateReadPreference, useWriteCommand, writeAsync
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getDatabaseName, getDurability, getName, getReadPreference, setDurability, setReadPreference
aggregateAsync, aggregateAsync, aggregateAsync, aggregateAsync, aggregateAsync, aggregateAsync, countAsync, countAsync, countAsync, countAsync, countAsync, countAsync, countAsync, countAsync, countAsync, countAsync, countAsync, countAsync, countAsync, countAsync, countAsync, countAsync, countAsync, countAsync, deleteAsync, deleteAsync, deleteAsync, deleteAsync, deleteAsync, deleteAsync, deleteAsync, deleteAsync, deleteAsync, deleteAsync, deleteAsync, deleteAsync, distinctAsync, distinctAsync, distinctAsync, distinctAsync, distinctAsync, distinctAsync, explainAsync, explainAsync, explainAsync, explainAsync, explainAsync, explainAsync, explainAsync, explainAsync, explainAsync, explainAsync, explainAsync, explainAsync, findAndModifyAsync, findAndModifyAsync, findAndModifyAsync, findAndModifyAsync, findAndModifyAsync, findAndModifyAsync, findAsync, findAsync, findAsync, findAsync, findAsync, findAsync, findAsync, findAsync, findAsync, findOneAsync, findOneAsync, findOneAsync, findOneAsync, findOneAsync, findOneAsync, findOneAsync, findOneAsync, findOneAsync, groupByAsync, groupByAsync, groupByAsync, groupByAsync, groupByAsync, groupByAsync, insertAsync, insertAsync, insertAsync, insertAsync, insertAsync, insertAsync, insertAsync, insertAsync, insertAsync, insertAsync, insertAsync, insertAsync, mapReduceAsync, mapReduceAsync, mapReduceAsync, mapReduceAsync, mapReduceAsync, mapReduceAsync, parallelScanAsync, parallelScanAsync, parallelScanAsync, parallelScanAsync, parallelScanAsync, parallelScanAsync, saveAsync, saveAsync, saveAsync, saveAsync, saveAsync, saveAsync, stream, stream, stream, stream, stream, stream, stream, stream, streamingFind, streamingFind, streamingFind, streamingFind, streamingFind, streamingFind, textSearchAsync, textSearchAsync, textSearchAsync, textSearchAsync, updateAsync, updateAsync, updateAsync, updateAsync, updateAsync, updateAsync, updateAsync, updateAsync, updateAsync, updateAsync, updateAsync, updateAsync, writeAsync, writeAsync, writeAsync, writeAsync, writeAsync, writeAsync
public SynchronousMongoCollectionImpl(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 MongoIterator<Document> aggregate(Aggregate command) throws MongoDbException
Overridden to call the AbstractAsyncMongoCollection.aggregateAsync(Aggregate)
.
aggregate
in interface MongoCollection
command
- The details of the aggregation request.MongoDbException
- On an error executing the aggregate command.AbstractAsyncMongoCollection.aggregateAsync(Aggregate)
public MongoIterator<Document> aggregate(Aggregate.Builder command) throws MongoDbException
Overridden to call the aggregate(Aggregate)
.
aggregate
in interface MongoCollection
command
- The details of the aggregation request.MongoDbException
- On an error executing the aggregate command.public long count() throws MongoDbException
This is equivalent to calling countAsync().get()
Overridden to call the count(DocumentAssignable,ReadPreference)
method with AbstractMongoOperations.getReadPreference()
as the readPreference
argument and an empty query
document.
count
in interface MongoCollection
MongoDbException
- On an error finding the documents.public long count(Count count) throws MongoDbException
Overridden to call the AbstractAsyncMongoCollection.countAsync(Count)
and unwrap the result.
count
in interface MongoCollection
count
- The count command.MongoDbException
- On an error counting the documents.public long count(Count.Builder count) throws MongoDbException
Overridden to call the count(count.build())
.
count
in interface MongoCollection
count
- The count command.MongoDbException
- On an error counting the documents.public long count(DocumentAssignable query) throws MongoDbException
This is equivalent to calling countAsync(...).get()
Overridden to call the count(DocumentAssignable, ReadPreference)
method with AbstractMongoOperations.getReadPreference()
as the readPreference
argument.
count
in interface MongoCollection
query
- The query document.MongoDbException
- On an error finding the documents.public long count(DocumentAssignable query, ReadPreference readPreference) throws MongoDbException
Overridden to call the
AbstractAsyncMongoCollection.countAsync(DocumentAssignable, ReadPreference)
method.
count
in interface MongoCollection
query
- The query document.readPreference
- The preference for which servers to use to retrieve the
results.MongoDbException
- On an error finding the documents.public long count(ReadPreference readPreference) throws MongoDbException
This is equivalent to calling countAsync().get()
Overridden to call the count(DocumentAssignable,ReadPreference)
method with an empty query
document.
count
in interface MongoCollection
readPreference
- The preference for which servers to use to retrieve the
results.MongoDbException
- On an error finding the documents.public void createIndex(boolean unique, Element... keys) throws MongoDbException
This method is intended to be used with the
Index
class's static methods:
import static
com.allanbank.mongodb.builder.Index.asc
; import staticcom.allanbank.mongodb.builder.Index.desc
; MongoCollection collection = ...; collection.createIndex( true, asc("f"), desc("g") ); ...
Overridden to call the createIndex(String, boolean, Element...)
method with null
for the name.
createIndex
in interface MongoCollection
unique
- If true then the index created will enforce entries are
unique.keys
- The keys to use for the index.MongoDbException
- On a failure building the index.createIndex(String, boolean, Element...)
public void createIndex(DocumentAssignable options, Element... keys) throws MongoDbException
This method is intended to be used with the
Index
class's static methods:
import static
com.allanbank.mongodb.bson.builder.BuilderFactory.start
; import staticcom.allanbank.mongodb.builder.Index.asc
; import staticcom.allanbank.mongodb.builder.Index.desc
; MongoCollection collection = ...; collection.createIndex(start().add("sparse", true), asc("f") ); ...
Overridden to call the
createIndex(String,DocumentAssignable,Element...)
method with
null
for name.
createIndex
in interface MongoCollection
options
- The options for the index.keys
- The keys to use for the index.MongoDbException
- On a failure building the index.createIndex(String,DocumentAssignable,Element...)
public void createIndex(Element... keys) throws MongoDbException
This method is intended to be used with the
Index
class's static methods:
import static
com.allanbank.mongodb.builder.Index.asc
; import staticcom.allanbank.mongodb.builder.Index.desc
; MongoCollection collection = ...; collection.createIndex( asc("f"), desc("g") ); ...
Overridden to call the
createIndex(DocumentAssignable, Element...)
method with
AbstractMongoOperations.EMPTY_INDEX_OPTIONS
for options.
createIndex
in interface MongoCollection
keys
- The keys to use for the index.MongoDbException
- On a failure building the index.createIndex(DocumentAssignable, Element...)
public void createIndex(String name, boolean unique, Element... keys) throws MongoDbException
This method is intended to be used with the
Index
class's static methods:
import static
com.allanbank.mongodb.builder.Index.asc
; import staticcom.allanbank.mongodb.builder.Index.desc
; MongoCollection collection = ...; collection.createIndex( "f_and_g", false, asc("f"), desc("g") ); ...
Overridden to call the
createIndex(String,DocumentAssignable,Element...)
method with
AbstractMongoOperations.UNIQUE_INDEX_OPTIONS
if unique
is true
or
AbstractMongoOperations.EMPTY_INDEX_OPTIONS
id unique
is false
.
createIndex
in interface MongoCollection
name
- The name of the index. If null
then a name is
generated based on the keys.unique
- If true then the index created will enforce entries are
unique.keys
- The keys to use for the index.MongoDbException
- On a failure building the index.createIndex(String, DocumentAssignable, Element...)
public void createIndex(String name, DocumentAssignable options, Element... keys) throws MongoDbException
This method is intended to be used with the
Index
class's static methods:
import static
com.allanbank.mongodb.bson.builder.BuilderFactory.start
; import staticcom.allanbank.mongodb.builder.Index.asc
; import staticcom.allanbank.mongodb.builder.Index.desc
; MongoCollection collection = ...; collection.createIndex("sparse_f", start().add("sparse", true), asc("f") ); ...
Overridden to insert the index document into the 'system.indexes'
collection or use the createIndexes
command as appropriate.
createIndex
in interface MongoCollection
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 long delete(DocumentAssignable query) throws MongoDbException
Overridden to call the
delete(DocumentAssignable, boolean, Durability)
method with
false as the singleDelete argument and the
default durability
.
delete
in interface MongoCollection
query
- Query to locate the documents to be deleted.MongoDbException
- On an error deleting the documents.delete(DocumentAssignable, boolean, Durability)
public long delete(DocumentAssignable query, boolean singleDelete) throws MongoDbException
Overridden to call the
delete(DocumentAssignable, boolean, Durability)
method with the
default durability
.
delete
in interface MongoCollection
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.MongoDbException
- On an error deleting the documents.delete(DocumentAssignable, boolean, Durability)
public long delete(DocumentAssignable query, boolean singleDelete, Durability durability) throws MongoDbException
Overridden to call the
AbstractAsyncMongoCollection.deleteAsync(DocumentAssignable, boolean, Durability)
method.
delete
in interface MongoCollection
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.AbstractAsyncMongoCollection.deleteAsync(DocumentAssignable, boolean, Durability)
public long delete(DocumentAssignable query, Durability durability) throws MongoDbException
Overridden to call the
AbstractAsyncMongoCollection.deleteAsync(DocumentAssignable, boolean, Durability)
method with
false as the singleDelete argument.
delete
in interface MongoCollection
query
- Query to locate the documents to be deleted.durability
- The durability for the delete.MongoDbException
- On an error deleting the documents.delete(DocumentAssignable, boolean, Durability)
public MongoIterator<Element> distinct(Distinct command) throws MongoDbException
Overridden to call the AbstractAsyncMongoCollection.distinctAsync(Distinct)
.
distinct
in interface MongoCollection
command
- The details of the distinct request.MongoDbException
- On an error finding the documents.public MongoIterator<Element> distinct(Distinct.Builder command) throws MongoDbException
Overridden to call the distinct(Distinct)
.
distinct
in interface MongoCollection
command
- The details of the distinct request.MongoDbException
- On an error finding the documents.public boolean drop()
Overridden to issue a { "drop" :
drop
in interface MongoCollection
MongoCollection.drop()
public boolean dropIndex(IntegerElement... keys) throws MongoDbException
This method is intended to be used with the
Index
class's static methods:
import static
com.allanbank.mongodb.builder.Index.asc
; import staticcom.allanbank.mongodb.builder.Index.desc
; MongoCollection collection = ...; collection.dropIndex( asc("f"), desc("g") ); ...
To generate the name of the index and then drop it.
dropIndex
in interface MongoCollection
keys
- The keys for the index to be dropped.MongoDbException
- On an error deleting the indexes.public boolean dropIndex(String name) throws MongoDbException
Overridden to issue a { "deleteIndexes" :
dropIndex
in interface MongoCollection
name
- The name of the index.MongoDbException
- On an error deleting the indexes.public boolean exists() throws MongoDbException
This method is simply a helper name to check if this collection's name
appears in the parent database's
list of
collections.
exists
in interface MongoCollection
MongoDbException
- On an error retrieving the list of collections.public Document explain(Aggregate aggregation) throws MongoDbException
This is equivalent to calling explainAsync(...).get()
Overridden to call the AbstractAsyncMongoCollection.explainAsync(Aggregate)
method.
explain
in interface MongoCollection
aggregation
- The aggregation details.MongoDbException
- On an error finding the documents.public Document explain(Aggregate.Builder aggregation) throws MongoDbException
This is equivalent to calling explainAsync(...).get()
Overridden to call the AbstractAsyncMongoCollection.explainAsync(Aggregate)
method.
explain
in interface MongoCollection
aggregation
- The aggregation details.MongoDbException
- On an error finding the documents.public Document explain(DocumentAssignable query) throws MongoDbException
Overridden to call the explain(Find)
method.
explain
in interface MongoCollection
query
- The query document.MongoDbException
- On an error finding the documents.explain(Find)
public Document explain(Find query) throws MongoDbException
This is equivalent to calling explainAsync(...).get()
Overridden to call the AbstractAsyncMongoCollection.explainAsync(Find)
method.
explain
in interface MongoCollection
query
- The query details.MongoDbException
- On an error finding the documents.AbstractAsyncMongoCollection.explainAsync(Find)
public Document explain(Find.Builder query) throws MongoDbException
This is equivalent to calling explainAsync(...).get()
Overridden to call the explain(Find)
method.
explain
in interface MongoCollection
query
- The query details.MongoDbException
- On an error finding the documents.public MongoIterator<Document> find(DocumentAssignable query) throws MongoDbException
This is equivalent to calling findAsync(...).get()
Overridden to call the AbstractAsyncMongoCollection.findAsync(DocumentAssignable)
method.
find
in interface MongoCollection
query
- The query document.MongoDbException
- On an error finding the documents.AbstractAsyncMongoCollection.findAsync(DocumentAssignable)
public MongoIterator<Document> find(Find query) throws MongoDbException
This is equivalent to calling findAsync(...).get()
Overridden to call the AbstractAsyncMongoCollection.findAsync(Find)
method.
find
in interface MongoCollection
query
- The query details.MongoDbException
- On an error finding the documents.AbstractAsyncMongoCollection.findAsync(Find)
public MongoIterator<Document> find(Find.Builder query) throws MongoDbException
This is equivalent to calling findAsync(...).get()
Overridden to call the find(Find)
method.
find
in interface MongoCollection
query
- The query details.MongoDbException
- On an error finding the documents.public Document findAndModify(FindAndModify command) throws MongoDbException
Overridden to call the AbstractAsyncMongoCollection.findAndModifyAsync(FindAndModify)
.
findAndModify
in interface MongoCollection
command
- The details of the find and modify request.MongoDbException
- On an error finding the documents.AbstractAsyncMongoCollection.findAndModifyAsync(FindAndModify)
public Document findAndModify(FindAndModify.Builder command) throws MongoDbException
Overridden to call the findAndModify(FindAndModify)
.
findAndModify
in interface MongoCollection
command
- The details of the find and modify request.MongoDbException
- On an error finding the documents.public Document findOne(DocumentAssignable query) throws MongoDbException
Overridden to call the AbstractAsyncMongoCollection.findOneAsync(DocumentAssignable)
.
findOne
in interface MongoCollection
query
- The query document.MongoDbException
- On an error finding the document.AbstractAsyncMongoCollection.findOneAsync(DocumentAssignable)
public Document findOne(Find query) throws MongoDbException
Overridden to call the
AbstractMongoOperations.findOneAsync(com.allanbank.mongodb.Callback, Find)
.
findOne
in interface MongoCollection
query
- The query details.MongoDbException
- On an error finding the document.AbstractMongoOperations.findOneAsync(com.allanbank.mongodb.Callback, Find)
public Document findOne(Find.Builder query) throws MongoDbException
Note that following options in the Find
class do not make sense
and are silently ignored by this method.
Batch Size
- Automatically set to 1.Limit
- Automatically set to 1.Tailable
- This method only returns 1
document.
Overridden to call the findOne(Find)
method.
findOne
in interface MongoCollection
query
- The query details.MongoDbException
- On an error finding the document.public MongoIterator<Element> groupBy(GroupBy command) throws MongoDbException
Overridden to call the AbstractAsyncMongoCollection.groupByAsync(GroupBy)
.
groupBy
in interface MongoCollection
command
- The details of the group request.MongoDbException
- On an error finding the documents.public MongoIterator<Element> groupBy(GroupBy.Builder command) throws MongoDbException
Overridden to call the groupBy(GroupBy)
.
groupBy
in interface MongoCollection
command
- The details of the group request.MongoDbException
- On an error finding the documents.public int insert(boolean continueOnError, DocumentAssignable... documents) throws MongoDbException
This is equivalent to calling
insertAsync(...).get()
Overridden to call the
insert(boolean, Durability, DocumentAssignable...)
method with
the default durability
.
insert
in interface MongoCollection
continueOnError
- If the insert should continue if one of the documents causes
an error.documents
- The documents to add to the collection.-1
.MongoDbException
- On an error inserting the documents.insert(boolean, Durability, DocumentAssignable[])
public int insert(boolean continueOnError, Durability durability, DocumentAssignable... documents) throws MongoDbException
This is equivalent to calling
insertAsync(...).get()
Overridden to call the
AbstractAsyncMongoCollection.insertAsync(boolean, Durability, DocumentAssignable...)
method.
insert
in interface MongoCollection
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.-1
.MongoDbException
- On an error inserting the documents.AbstractAsyncMongoCollection.insertAsync(boolean, Durability, DocumentAssignable[])
public int insert(DocumentAssignable... documents) throws MongoDbException
This is equivalent to calling
insertAsync(...).get()
Overridden to call the
insert(boolean, Durability, DocumentAssignable...)
method with
continueOnError set to false and the default durability
.
insert
in interface MongoCollection
documents
- The documents to add to the collection.-1
.MongoDbException
- On an error inserting the documents.AsyncMongoCollection.insertAsync(boolean, Durability,
DocumentAssignable[])
public int insert(Durability durability, DocumentAssignable... documents) throws MongoDbException
This is equivalent to calling
insertAsync(...).get()
Overridden to call the
insert(boolean, Durability, DocumentAssignable...)
method with
continueOnError set to false.
insert
in interface MongoCollection
durability
- The durability for the insert.documents
- The documents to add to the collection.-1
.MongoDbException
- On an error inserting the documents.insert(boolean, Durability, DocumentAssignable[])
public boolean isCapped() throws MongoDbException
statistics
indicate that
the collection is a capped collection.
Overridden to send a collStats
command to the MongoDB server and
look for the capped
field to determine if the collection is
capped or not.
isCapped
in interface MongoCollection
statistics
indicate that
the collection is a capped collection.MongoDbException
- On an error collecting the collection statistics.MongoCollection.isCapped()
public MongoIterator<Document> mapReduce(MapReduce command) throws MongoDbException
Overridden to call the AbstractAsyncMongoCollection.mapReduceAsync(MapReduce)
.
mapReduce
in interface MongoCollection
command
- The details of the map/reduce request.MongoDbException
- On an error finding the documents.AbstractAsyncMongoCollection.mapReduceAsync(MapReduce)
public MongoIterator<Document> mapReduce(MapReduce.Builder command) throws MongoDbException
Overridden to call the mapReduce(MapReduce)
.
mapReduce
in interface MongoCollection
command
- The details of the map/reduce request.MongoDbException
- On an error finding the documents.public Collection<MongoIterator<Document>> parallelScan(ParallelScan parallelScan) throws MongoDbException
parallelCollectionScan
command to open multiple
iterators over the collection each configured to scan a distinct regions
of the collection. You may then use a separate thread to scan each region
of the collection in parallel.
Overridden to call the AbstractAsyncMongoCollection.parallelScanAsync(ParallelScan)
.
parallelScan
in interface MongoCollection
parallelScan
- The details on the scan.MongoDbException
- On an error initializing the parallel scan.AbstractAsyncMongoCollection.parallelScanAsync(ParallelScan)
public Collection<MongoIterator<Document>> parallelScan(ParallelScan.Builder parallelScan) throws MongoDbException
parallelCollectionScan
command to open multiple
iterators over the collection each configured to scan a distinct regions
of the collection. You may then use a separate thread to scan each region
of the collection in parallel.
Overridden to call the parallelScan(ParallelScan)
.
parallelScan
in interface MongoCollection
parallelScan
- The details on the scan.MongoDbException
- On an error initializing the parallel scan.AbstractAsyncMongoCollection.parallelScanAsync(ParallelScan)
public int save(DocumentAssignable document) throws MongoDbException
document
to the collection.
If the document
does not contain an _id
field then this
method is equivalent to: insert(document)
.
If the document
does contain an _id
field then this
method is equivalent to:
update(BuilderFactory.start().add(document.get("_id")), document, false,
true)
.
Overridden to call the save(DocumentAssignable, Durability)
using the default durability
.
save
in interface MongoCollection
document
- The document to save to the collection.MongoDbException
- On an error saving the documents.public int save(DocumentAssignable document, Durability durability) throws MongoDbException
document
to the collection.
If the document
does not contain an _id
field then this
method is equivalent to:
insert(durability,
document)
.
If the document
does contain an _id
field then this
method is equivalent to:
update(BuilderFactory.start().add(document.get("_id")), document, false,
true, durability)
.
Overridden to call the AbstractAsyncMongoCollection.saveAsync(DocumentAssignable, Durability)
.
save
in interface MongoCollection
document
- The document to save to the collection.durability
- The durability for the save.MongoDbException
- On an error saving the documents.public BatchedAsyncMongoCollection startBatch()
Overridden to return a BatchedAsyncMongoCollection
.
startBatch
in interface MongoCollection
BatchedAsyncMongoCollection.close()
method must be called
to submit the batch of requests.public Document stats() throws MongoDbException
Overridden to send a collStats
command to the MongoDB server.
stats
in interface MongoCollection
MongoDbException
- On an error collecting the collection statistics.MongoCollection.stats()
@Deprecated public MongoIterator<TextResult> textSearch(Text command) throws MongoDbException
text
command was deprecated in the
2.6 version of MongoDB. Use the
$text
query operator
instead. This method will not be removed until two releases
after the MongoDB 2.6 release (e.g. 2.10 if the releases are
2.8 and 2.10).text
command on the server.
Overridden to call the
AbstractAsyncMongoCollection.textSearchAsync(com.allanbank.mongodb.builder.Text)
.
textSearch
in interface MongoCollection
command
- The details of the text
request.text
results returned.MongoDbException
- On an error executing the text
command.AbstractAsyncMongoCollection.textSearchAsync(com.allanbank.mongodb.builder.Text)
@Deprecated public MongoIterator<TextResult> textSearch(Text.Builder command) throws MongoDbException
text
command was deprecated in the
2.6 version of MongoDB. Use the
$text
query operator
instead. This method will not be removed until two releases
after the MongoDB 2.6 release (e.g. 2.10 if the releases are
2.8 and 2.10).text
command on the server.
Overridden to call the
textSearch(com.allanbank.mongodb.builder.Text)
.
textSearch
in interface MongoCollection
command
- The details of the text
request.text
results returned.MongoDbException
- On an error executing the text
command.public long update(DocumentAssignable query, DocumentAssignable update) throws MongoDbException
Overridden to call the
update(DocumentAssignable, DocumentAssignable, boolean, boolean, Durability)
method with multiUpdate set to true, upsert set to false, and using the
default durability
.
update
in interface MongoCollection
query
- The query to select the documents to update.update
- The updates to apply to the selected documents.MongoDbException
- On an error updating the documents.update(DocumentAssignable, DocumentAssignable, boolean, boolean,
Durability)
public long update(DocumentAssignable query, DocumentAssignable update, boolean multiUpdate, boolean upsert) throws MongoDbException
Overridden to call the
update(DocumentAssignable, DocumentAssignable, boolean, boolean, Durability)
method with the default durability
.
update
in interface MongoCollection
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.MongoDbException
- On an error updating the documents.update(DocumentAssignable, DocumentAssignable, boolean, boolean,
Durability)
public long update(DocumentAssignable query, DocumentAssignable update, boolean multiUpdate, boolean upsert, Durability durability) throws MongoDbException
Overridden to call the
AbstractAsyncMongoCollection.updateAsync(DocumentAssignable, DocumentAssignable, boolean, boolean, Durability)
method.
update
in interface MongoCollection
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 insert.MongoDbException
- On an error updating the documents.AbstractAsyncMongoCollection.updateAsync(DocumentAssignable, DocumentAssignable, boolean,
boolean, Durability)
public long update(DocumentAssignable query, DocumentAssignable update, Durability durability) throws MongoDbException
Overridden to call the
update(DocumentAssignable, DocumentAssignable, boolean, boolean, Durability)
method with multiUpdate set to true, and upsert set to false.
update
in interface MongoCollection
query
- The query to select the documents to update.update
- The updates to apply to the selected documents.durability
- The durability for the update.MongoDbException
- On an error updating the documents.update(DocumentAssignable, DocumentAssignable, boolean, boolean,
Durability)
public Document updateOptions(DocumentAssignable options) throws MongoDbException
collMod
command. The return value is the response from the MongoDB server and
normally contains a <name>_old
field for each
successfully set option on the collection. MongoCollection collection = ...; collection.updateOptions( BuilderFactory.start().add( "usePowerOf2Sizes", true ) );
Overridden to send a collMod
command to the server.
updateOptions
in interface MongoCollection
options
- The collection options to be set.MongoDbException
- On an error validating the collection.public Document validate(MongoCollection.ValidateMode mode) throws MongoDbException
Overridden to send a validate
command to the server.
validate
in interface MongoCollection
mode
- The validation mode to use.MongoDbException
- On an error validating the collection.public long write(BatchedWrite write) throws MongoDbException
If connected to a cluster where all servers can accept write commands then the operations will be sent to the server using the write commands. If the cluster does not support the write command then the operations will be converted to a series of native write operations.
Since this method may use the write commands a Durability
of
Durability.NONE
will be changed to Durability.ACK
.
Overridden to call the AbstractAsyncMongoCollection.writeAsync(BatchedWrite)
.
write
in interface MongoCollection
write
- The batched writesreturn
for the MongoCollection.insert(DocumentAssignable...)
method applies.MongoDbException
- On an error submitting the write operations.AbstractAsyncMongoCollection.writeAsync(BatchedWrite)
public long write(BatchedWrite.Builder write) throws MongoDbException
If connected to a cluster where all servers can accept write commands then the operations will be sent to the server using the write commands. If the cluster does not support the write command then the operations will be converted to a series of native write operations.
Since this method may use the write commands a Durability
of
Durability.NONE
will be changed to Durability.ACK
.
Overridden to call the write(BatchedWrite)
.
write
in interface MongoCollection
write
- The batched writesreturn
for the MongoCollection.insert(DocumentAssignable...)
method applies.MongoDbException
- On an error submitting the write operations.write(BatchedWrite)
protected void addOptions(String command, DocumentAssignable options, DocumentBuilder builder)
command
- The command to make sure is removed from the options.options
- The options to be added. May be null
.builder
- The builder to add the options to.protected Version determineIndexServerVersion(Element[] keys)
keys
- The index keys.protected boolean isCreateIndexesSupported()
createIndexes
command.BatchedWrite.REQUIRED_VERSION
.Copyright © 2011–2014 Allanbank Consulting, Inc.. All rights reserved.