Class DBCollection
- java.lang.Object
-
- com.mongodb.DBCollection
-
@ThreadSafe @Deprecated(since="2021-05-27") public class DBCollection extends java.lang.Object
Deprecated.Usage of this API is not supported in AEM as a Cloud Service.Implementation of a database collection. A typical invocation sequence is thus:MongoClient mongoClient = new MongoClient(new ServerAddress("localhost", 27017)); DB db = mongoClient.getDB("mydb"); DBCollection collection = db.getCollection("test");
DBCollection coll = db.getCollection("testCollection");
BasicDBObject doc = new BasicDBObject("name", "MongoDB").append("type", "database") .append("count", 1) .append("info", new BasicDBObject("x", 203).append("y", 102)); coll.insert(doc);
DBObject myDoc = coll.findOne(); System.out.println(myDoc);
Mongo.getDB(String)
for further information about the effective deprecation of this class.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
ID_FIELD_NAME
Deprecated.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addOption(int option)
Deprecated.Replaced withDBCursor.addOption(int)
AggregationOutput
aggregate(DBObject firstOp, DBObject... additionalOps)
Deprecated.Useaggregate(List, AggregationOptions)
insteadAggregationOutput
aggregate(java.util.List<? extends DBObject> pipeline)
Deprecated.Useaggregate(List, AggregationOptions)
insteadCursor
aggregate(java.util.List<? extends DBObject> pipeline, AggregationOptions options)
Deprecated.Method implements aggregation framework.Cursor
aggregate(java.util.List<? extends DBObject> pipeline, AggregationOptions options, ReadPreference readPreference)
Deprecated.Method implements aggregation framework.AggregationOutput
aggregate(java.util.List<? extends DBObject> pipeline, ReadPreference readPreference)
Deprecated.Useaggregate(List, AggregationOptions, ReadPreference)
)} insteadlong
count()
Deprecated.Same asgetCount()
long
count(DBObject query)
Deprecated.Same asgetCount(DBObject)
long
count(DBObject query, DBCollectionCountOptions options)
Deprecated.Get the count of documents in collection that would match a criteria.long
count(DBObject query, ReadPreference readPreference)
Deprecated.Get the count of documents in collection that would match a criteria.void
createIndex(DBObject keys)
Deprecated.Creates an index on the field specified, if that index does not already exist.void
createIndex(DBObject keys, DBObject options)
Deprecated.Creates an index on the field specified, if that index does not already exist.void
createIndex(DBObject keys, java.lang.String name)
Deprecated.Forces creation of an index on a set of fields, if one does not already exist.void
createIndex(DBObject keys, java.lang.String name, boolean unique)
Deprecated.Forces creation of an index on a set of fields, if one does not already exist.void
createIndex(java.lang.String name)
Deprecated.Forces creation of an ascending index on a field with the default options.java.util.List
distinct(java.lang.String fieldName)
Deprecated.Find the distinct values for a specified field across a collection and returns the results in an array.java.util.List
distinct(java.lang.String fieldName, DBCollectionDistinctOptions options)
Deprecated.Find the distinct values for a specified field across a collection and returns the results in an array.java.util.List
distinct(java.lang.String fieldName, DBObject query)
Deprecated.Find the distinct values for a specified field across a collection and returns the results in an array.java.util.List
distinct(java.lang.String fieldName, DBObject query, ReadPreference readPreference)
Deprecated.Find the distinct values for a specified field across a collection and returns the results in an array.java.util.List
distinct(java.lang.String fieldName, ReadPreference readPreference)
Deprecated.Find the distinct values for a specified field across a collection and returns the results in an array.void
drop()
Deprecated.Drops (deletes) this collection from the database.void
dropIndex(DBObject index)
Deprecated.Drops an index from this collection.void
dropIndex(java.lang.String indexName)
Deprecated.Drops the index with the given name from this collection.void
dropIndexes()
Deprecated.Drop all indexes on this collection.void
dropIndexes(java.lang.String indexName)
Deprecated.Drops the index with the given name from this collection.CommandResult
explainAggregate(java.util.List<? extends DBObject> pipeline, AggregationOptions options)
Deprecated.Return the explain plan for the aggregation pipeline.DBCursor
find()
Deprecated.Select all documents in collection and get a cursor to the selected documents.DBCursor
find(DBObject query)
Deprecated.Select documents in collection and get a cursor to the selected documents.DBCursor
find(DBObject query, DBCollectionFindOptions options)
Deprecated.Select documents in collection and get a cursor to the selected documents.DBCursor
find(DBObject query, DBObject projection)
Deprecated.Select documents in collection and get a cursor to the selected documents.DBCursor
find(DBObject query, DBObject projection, int numToSkip, int batchSize)
Deprecated.useDBCursor.skip(int)
andDBCursor.batchSize(int)
on theDBCursor
returned fromfind(DBObject, DBObject)
DBCursor
find(DBObject query, DBObject projection, int numToSkip, int batchSize, int options)
Deprecated.useDBCursor.skip(int)
,DBCursor.batchSize(int)
andDBCursor.setOptions(int)
on theDBCursor
returned fromfind(DBObject, DBObject)
DBObject
findAndModify(DBObject query, DBCollectionFindAndModifyOptions options)
Deprecated.Atomically modify and return a single document.DBObject
findAndModify(DBObject query, DBObject update)
Deprecated.Atomically modify and return a single document.DBObject
findAndModify(DBObject query, DBObject sort, DBObject update)
Deprecated.Atomically modify and return a single document.DBObject
findAndModify(DBObject query, DBObject fields, DBObject sort, boolean remove, DBObject update, boolean returnNew, boolean upsert)
Deprecated.Atomically modify and return a single document.DBObject
findAndModify(DBObject query, DBObject fields, DBObject sort, boolean remove, DBObject update, boolean returnNew, boolean upsert, boolean bypassDocumentValidation, long maxTime, java.util.concurrent.TimeUnit maxTimeUnit)
Deprecated.Atomically modify and return a single document.DBObject
findAndModify(DBObject query, DBObject fields, DBObject sort, boolean remove, DBObject update, boolean returnNew, boolean upsert, boolean bypassDocumentValidation, long maxTime, java.util.concurrent.TimeUnit maxTimeUnit, WriteConcern writeConcern)
Deprecated.Atomically modify and return a single document.DBObject
findAndModify(DBObject query, DBObject fields, DBObject sort, boolean remove, DBObject update, boolean returnNew, boolean upsert, long maxTime, java.util.concurrent.TimeUnit maxTimeUnit)
Deprecated.Atomically modify and return a single document.DBObject
findAndModify(DBObject query, DBObject fields, DBObject sort, boolean remove, DBObject update, boolean returnNew, boolean upsert, long maxTime, java.util.concurrent.TimeUnit maxTimeUnit, WriteConcern writeConcern)
Deprecated.Atomically modify and return a single document.DBObject
findAndModify(DBObject query, DBObject fields, DBObject sort, boolean remove, DBObject update, boolean returnNew, boolean upsert, WriteConcern writeConcern)
Deprecated.Atomically modify and return a single document.DBObject
findAndRemove(DBObject query)
Deprecated.Atomically remove and return a single document.DBObject
findOne()
Deprecated.Get a single document from collection.DBObject
findOne(DBObject query)
Deprecated.Get a single document from collection.DBObject
findOne(DBObject query, DBCollectionFindOptions findOptions)
Deprecated.Get a single document from collection.DBObject
findOne(DBObject query, DBObject projection)
Deprecated.Get a single document from collection.DBObject
findOne(DBObject query, DBObject projection, DBObject sort)
Deprecated.Get a single document from collection.DBObject
findOne(DBObject query, DBObject projection, DBObject sort, ReadPreference readPreference)
Deprecated.Get a single document from collection.DBObject
findOne(DBObject query, DBObject projection, ReadPreference readPreference)
Deprecated.Get a single document from collection.DBObject
findOne(java.lang.Object id)
Deprecated.Get a single document from collection by '_id'.DBObject
findOne(java.lang.Object id, DBObject projection)
Deprecated.Get a single document from collection by '_id'.DBCollection
getCollection(java.lang.String name)
Deprecated.Find a collection that is prefixed with this collection's name.long
getCount()
Deprecated.Get the count of documents in collection.long
getCount(DBObject query)
Deprecated.Get the count of documents in collection that would match a criteria.long
getCount(DBObject query, DBCollectionCountOptions options)
Deprecated.Get the count of documents in collection that would match a criteria.long
getCount(DBObject query, DBObject projection)
Deprecated.long
getCount(DBObject query, DBObject projection, long limit, long skip)
Deprecated.long
getCount(DBObject query, DBObject projection, long limit, long skip, ReadPreference readPreference)
Deprecated.long
getCount(DBObject query, DBObject projection, ReadPreference readPreference)
Deprecated.long
getCount(ReadPreference readPreference)
Deprecated.Get the count of documents in collection.DB
getDB()
Deprecated.Returns the database this collection is a member of.DBDecoderFactory
getDBDecoderFactory()
Deprecated.Get the decoder factory for this collection.DBEncoderFactory
getDBEncoderFactory()
Deprecated.Get the encoder factory for this collection.java.lang.String
getFullName()
Deprecated.Get the full name of a collection, with the database name as a prefix.java.util.List<DBObject>
getHintFields()
Deprecated.PreferDBCursor.hint(DBObject)
java.util.List<DBObject>
getIndexInfo()
Deprecated.Return a list of the indexes for this collection.java.lang.String
getName()
Deprecated.Get the name of a collection.java.lang.Class
getObjectClass()
Deprecated.Gets the default class for objects in the collectionint
getOptions()
Deprecated.Replaced withDBCursor.getOptions()
ReadConcern
getReadConcern()
Deprecated.Get the read concern for this collection.ReadPreference
getReadPreference()
Deprecated.Gets theReadPreference
.CommandResult
getStats()
Deprecated.The collStats command returns a variety of storage statistics for a given collectionWriteConcern
getWriteConcern()
Deprecated.Get theWriteConcern
for this collection.DBObject
group(DBObject key, DBObject cond, DBObject initial, java.lang.String reduce)
Deprecated.The group command was deprecated in MongoDB 3.4DBObject
group(DBObject key, DBObject cond, DBObject initial, java.lang.String reduce, java.lang.String finalize)
Deprecated.The group command was deprecated in MongoDB 3.4DBObject
group(DBObject key, DBObject cond, DBObject initial, java.lang.String reduce, java.lang.String finalize, ReadPreference readPreference)
Deprecated.The group command was deprecated in MongoDB 3.4DBObject
group(GroupCommand cmd)
Deprecated.The group command was deprecated in MongoDB 3.4DBObject
group(GroupCommand cmd, ReadPreference readPreference)
Deprecated.The group command was deprecated in MongoDB 3.4BulkWriteOperation
initializeOrderedBulkOperation()
Deprecated.Creates a builder for an ordered bulk write operation, consisting of an ordered collection of write requests, which can be any combination of inserts, updates, replaces, or removes.BulkWriteOperation
initializeUnorderedBulkOperation()
Deprecated.Creates a builder for an unordered bulk operation, consisting of an unordered collection of write requests, which can be any combination of inserts, updates, replaces, or removes.WriteResult
insert(DBObject... documents)
Deprecated.Insert documents into a collection.WriteResult
insert(DBObject[] documents, WriteConcern writeConcern)
Deprecated.Insert documents into a collection.WriteResult
insert(DBObject[] documents, WriteConcern aWriteConcern, DBEncoder encoder)
Deprecated.Insert documents into a collection.WriteResult
insert(DBObject document, WriteConcern writeConcern)
Deprecated.Insert a document into a collection.WriteResult
insert(WriteConcern writeConcern, DBObject... documents)
Deprecated.Insert documents into a collection.WriteResult
insert(java.util.List<? extends DBObject> documents)
Deprecated.Insert documents into a collection.WriteResult
insert(java.util.List<? extends DBObject> documents, InsertOptions insertOptions)
Deprecated.Insert documents into a collection.WriteResult
insert(java.util.List<? extends DBObject> documents, WriteConcern aWriteConcern)
Deprecated.Insert documents into a collection.WriteResult
insert(java.util.List<? extends DBObject> documents, WriteConcern aWriteConcern, DBEncoder dbEncoder)
Deprecated.Insert documents into a collection.boolean
isCapped()
Deprecated.Checks whether this collection is cappedMapReduceOutput
mapReduce(MapReduceCommand command)
Deprecated.Allows you to run map-reduce aggregation operations over a collection.MapReduceOutput
mapReduce(java.lang.String map, java.lang.String reduce, java.lang.String outputTarget, DBObject query)
Deprecated.Allows you to run map-reduce aggregation operations over a collection.MapReduceOutput
mapReduce(java.lang.String map, java.lang.String reduce, java.lang.String outputTarget, MapReduceCommand.OutputType outputType, DBObject query)
Deprecated.Allows you to run map-reduce aggregation operations over a collection and saves to a named collection.MapReduceOutput
mapReduce(java.lang.String map, java.lang.String reduce, java.lang.String outputTarget, MapReduceCommand.OutputType outputType, DBObject query, ReadPreference readPreference)
Deprecated.Allows you to run map-reduce aggregation operations over a collection and saves to a named collection.java.util.List<Cursor>
parallelScan(ParallelScanOptions options)
Deprecated.the parallelCollectionScan command will be removed in MongoDB 4.2WriteResult
remove(DBObject query)
Deprecated.Remove documents from a collection.WriteResult
remove(DBObject query, DBCollectionRemoveOptions options)
Deprecated.Remove documents from a collection.WriteResult
remove(DBObject query, WriteConcern writeConcern)
Deprecated.Remove documents from a collection.WriteResult
remove(DBObject query, WriteConcern writeConcern, DBEncoder encoder)
Deprecated.Remove documents from a collection.DBCollection
rename(java.lang.String newName)
Deprecated.Change the name of an existing collection.DBCollection
rename(java.lang.String newName, boolean dropTarget)
Deprecated.Change the name of an existing collection.void
resetOptions()
Deprecated.Replaced withDBCursor.resetOptions()
WriteResult
save(DBObject document)
Deprecated.Update an existing document or insert a document depending on the parameter.WriteResult
save(DBObject document, WriteConcern writeConcern)
Deprecated.Update an existing document or insert a document depending on the parameter.void
setDBDecoderFactory(DBDecoderFactory factory)
Deprecated.Set a custom decoder factory for this collection.void
setDBEncoderFactory(DBEncoderFactory factory)
Deprecated.Set a custom encoder factory for this collection.void
setHintFields(java.util.List<? extends DBObject> indexes)
Deprecated.PreferDBCursor.hint(DBObject)
void
setInternalClass(java.lang.String path, java.lang.Class<? extends DBObject> aClass)
Deprecated.Sets the internal class for the given path in the document hierarchyvoid
setObjectClass(java.lang.Class<? extends DBObject> aClass)
Deprecated.Sets a default class for objects in this collection; null resets the class to nothing.void
setOptions(int options)
Deprecated.Replaced withDBCursor.setOptions(int)
void
setReadConcern(ReadConcern readConcern)
Deprecated.Sets the read concern for this collection.void
setReadPreference(ReadPreference preference)
Deprecated.Sets theReadPreference
for this collection.void
setWriteConcern(WriteConcern writeConcern)
Deprecated.Set theWriteConcern
for this collection.void
slaveOk()
Deprecated.Replaced withReadPreference.secondaryPreferred()
java.lang.String
toString()
Deprecated.WriteResult
update(DBObject query, DBObject update)
Deprecated.Modify an existing document.WriteResult
update(DBObject query, DBObject update, boolean upsert, boolean multi)
Deprecated.Modify an existing document or documents in collection.WriteResult
update(DBObject query, DBObject update, boolean upsert, boolean multi, WriteConcern aWriteConcern)
Deprecated.Modify an existing document or documents in collection.WriteResult
update(DBObject query, DBObject update, boolean upsert, boolean multi, WriteConcern concern, DBEncoder encoder)
Deprecated.Modify an existing document or documents in collection.WriteResult
update(DBObject query, DBObject update, boolean upsert, boolean multi, WriteConcern concern, java.lang.Boolean bypassDocumentValidation, DBEncoder encoder)
Deprecated.Modify an existing document or documents in collection.WriteResult
update(DBObject query, DBObject update, DBCollectionUpdateOptions options)
Deprecated.Modify an existing document or documents in collection.WriteResult
updateMulti(DBObject query, DBObject update)
Deprecated.Modify documents in collection.
-
-
-
Field Detail
-
ID_FIELD_NAME
public static final java.lang.String ID_FIELD_NAME
Deprecated.- See Also:
- Constant Field Values
-
-
Method Detail
-
insert
public WriteResult insert(DBObject document, WriteConcern writeConcern)
Deprecated.Insert a document into a collection. If the collection does not exists on the server, then it will be created. If the new document does not contain an '_id' field, it will be added.- Parameters:
document
-DBObject
to be insertedwriteConcern
-WriteConcern
to be used during operation- Returns:
- the result of the operation
- Throws:
DuplicateKeyException
- if the write failed to a duplicate unique keyWriteConcernException
- if the write failed due some other failure specific to the insert commandMongoCommandException
- if the write failed due to a specific command exceptionMongoException
- if the operation failed for some other reason
-
insert
public WriteResult insert(DBObject... documents)
Deprecated.Insert documents into a collection. If the collection does not exists on the server, then it will be created. If the new document does not contain an '_id' field, it will be added. Collection wideWriteConcern
will be used.- Parameters:
documents
-DBObject
's to be inserted- Returns:
- the result of the operation
- Throws:
DuplicateKeyException
- if the write failed to a duplicate unique keyWriteConcernException
- if the write failed due some other failure specific to the insert commandMongoCommandException
- if the write failed due to a specific command exceptionMongoException
- if the operation failed for some other reason
-
insert
public WriteResult insert(WriteConcern writeConcern, DBObject... documents)
Deprecated.Insert documents into a collection. If the collection does not exists on the server, then it will be created. If the new document does not contain an '_id' field, it will be added.- Parameters:
documents
-DBObject
's to be insertedwriteConcern
-WriteConcern
to be used during operation- Returns:
- the result of the operation
- Throws:
MongoCommandException
- if the write failed due to a specific command exceptionMongoException
- if the write failed due some other failure
-
insert
public WriteResult insert(DBObject[] documents, WriteConcern writeConcern)
Deprecated.Insert documents into a collection. If the collection does not exists on the server, then it will be created. If the new document does not contain an '_id' field, it will be added.- Parameters:
documents
-DBObject
's to be insertedwriteConcern
-WriteConcern
to be used during operation- Returns:
- the result of the operation
- Throws:
DuplicateKeyException
- if the write failed to a duplicate unique keyWriteConcernException
- if the write failed due some other failure specific to the insert commandMongoCommandException
- if the write failed due to a specific command exceptionMongoException
- if the operation failed for some other reason
-
insert
public WriteResult insert(java.util.List<? extends DBObject> documents)
Deprecated.Insert documents into a collection. If the collection does not exists on the server, then it will be created. If the new document does not contain an '_id' field, it will be added.- Parameters:
documents
- list ofDBObject
to be inserted- Returns:
- the result of the operation
- Throws:
DuplicateKeyException
- if the write failed to a duplicate unique keyWriteConcernException
- if the write failed due some other failure specific to the insert commandMongoCommandException
- if the write failed due to a specific command exceptionMongoException
- if the operation failed for some other reason
-
insert
public WriteResult insert(java.util.List<? extends DBObject> documents, WriteConcern aWriteConcern)
Deprecated.Insert documents into a collection. If the collection does not exists on the server, then it will be created. If the new document does not contain an '_id' field, it will be added.- Parameters:
documents
- list ofDBObject
's to be insertedaWriteConcern
-WriteConcern
to be used during operation- Returns:
- the result of the operation
- Throws:
DuplicateKeyException
- if the write failed to a duplicate unique keyWriteConcernException
- if the write failed due some other failure specific to the insert commandMongoCommandException
- if the write failed due to a specific command exceptionMongoException
- if the operation failed for some other reason
-
insert
public WriteResult insert(DBObject[] documents, WriteConcern aWriteConcern, DBEncoder encoder)
Deprecated.Insert documents into a collection. If the collection does not exists on the server, then it will be created. If the new document does not contain an '_id' field, it will be added.- Parameters:
documents
-DBObject
's to be insertedaWriteConcern
-WriteConcern
to be used during operationencoder
-DBEncoder
to be used- Returns:
- the result of the operation
- Throws:
DuplicateKeyException
- if the write failed to a duplicate unique keyWriteConcernException
- if the write failed due some other failure specific to the insert commandMongoCommandException
- if the write failed due to a specific command exceptionMongoException
- if the operation failed for some other reason
-
insert
public WriteResult insert(java.util.List<? extends DBObject> documents, WriteConcern aWriteConcern, @Nullable DBEncoder dbEncoder)
Deprecated.Insert documents into a collection. If the collection does not exists on the server, then it will be created. If the new document does not contain an '_id' field, it will be added.- Parameters:
documents
- a list ofDBObject
's to be insertedaWriteConcern
-WriteConcern
to be used during operationdbEncoder
-DBEncoder
to be used- Returns:
- the result of the operation
- Throws:
DuplicateKeyException
- if the write failed to a duplicate unique keyWriteConcernException
- if the write failed due some other failure specific to the insert commandMongoCommandException
- if the write failed due to a specific command exceptionMongoException
- if the operation failed for some other reason
-
insert
public WriteResult insert(java.util.List<? extends DBObject> documents, InsertOptions insertOptions)
Deprecated.Insert documents into a collection. If the collection does not exists on the server, then it will be created. If the new document does not contain an '_id' field, it will be added.
If the value of the continueOnError property of the given
InsertOptions
is true, that value will override the value of the continueOnError property of the givenWriteConcern
. Otherwise, the value of the continueOnError property of the givenWriteConcern
will take effect.- Parameters:
documents
- a list ofDBObject
's to be insertedinsertOptions
- the options to use for the insert- Returns:
- the result of the operation
- Throws:
DuplicateKeyException
- if the write failed to a duplicate unique keyWriteConcernException
- if the write failed due some other failure specific to the insert commandMongoCommandException
- if the write failed due to a specific command exceptionMongoException
- if the operation failed for some other reason
-
save
public WriteResult save(DBObject document)
Deprecated.Update an existing document or insert a document depending on the parameter. If the document does not contain an '_id' field, then the method performs an insert with the specified fields in the document as well as an '_id' field with a unique objectId value. If the document contains an '_id' field, then the method performs an upsert querying the collection on the '_id' field:- If a document does not exist with the specified '_id' value, the method performs an insert with the specified fields in the document.
- If a document exists with the specified '_id' value, the method performs an update, replacing all field in the existing record with the fields from the document.
- Parameters:
document
-DBObject
to save to the collection.- Returns:
- the result of the operation
- Throws:
DuplicateKeyException
- if the write failed to a duplicate unique keyWriteConcernException
- if the write failed due some other failure specific to the insert or update commandMongoCommandException
- if the write failed due to a specific command exceptionMongoException
- if the operation failed for some other reason
-
save
public WriteResult save(DBObject document, WriteConcern writeConcern)
Deprecated.Update an existing document or insert a document depending on the parameter. If the document does not contain an '_id' field, then the method performs an insert with the specified fields in the document as well as an '_id' field with a unique objectId value. If the document contains an '_id' field, then the method performs an upsert querying the collection on the '_id' field:- If a document does not exist with the specified '_id' value, the method performs an insert with the specified fields in the document.
- If a document exists with the specified '_id' value, the method performs an update, replacing all field in the existing record with the fields from the document.
- Parameters:
document
-DBObject
to save to the collection.writeConcern
-WriteConcern
to be used during operation- Returns:
- the result of the operation
- Throws:
DuplicateKeyException
- if the write failed to a duplicate unique keyWriteConcernException
- if the write failed due some other failure specific to the insert or update commandMongoCommandException
- if the write failed due to a specific command exceptionMongoException
- if the operation failed for some other reason
-
update
public WriteResult update(DBObject query, DBObject update, boolean upsert, boolean multi, WriteConcern aWriteConcern)
Deprecated.Modify an existing document or documents in collection. The query parameter employs the same query selectors, as used infind()
.- Parameters:
query
- the selection criteria for the updateupdate
- the modifications to applyupsert
- when true, inserts a document if no document matches the update query criteriamulti
- when true, updates all documents in the collection that match the update query criteria, otherwise only updates oneaWriteConcern
-WriteConcern
to be used during operation- Returns:
- the result of the operation
- Throws:
DuplicateKeyException
- if the write failed to a duplicate unique keyWriteConcernException
- if the write failed due some other failure specific to the update commandMongoCommandException
- if the write failed due to a specific command exceptionMongoException
- if the operation failed for some other reason
-
update
public WriteResult update(DBObject query, DBObject update, boolean upsert, boolean multi, WriteConcern concern, @Nullable DBEncoder encoder)
Deprecated.Modify an existing document or documents in collection. By default the method updates a single document. The query parameter employs the same query selectors, as used infind()
.- Parameters:
query
- the selection criteria for the updateupdate
- the modifications to applyupsert
- when true, inserts a document if no document matches the update query criteriamulti
- when true, updates all documents in the collection that match the update query criteria, otherwise only updates oneconcern
-WriteConcern
to be used during operationencoder
-DBEncoder
to be used- Returns:
- the result of the operation
- Throws:
DuplicateKeyException
- if the write failed to a duplicate unique keyWriteConcernException
- if the write failed due some other failure specific to the update commandMongoCommandException
- if the write failed due to a specific command exceptionMongoException
- if the operation failed for some other reason
-
update
public WriteResult update(DBObject query, DBObject update, boolean upsert, boolean multi, WriteConcern concern, @Nullable java.lang.Boolean bypassDocumentValidation, @Nullable DBEncoder encoder)
Deprecated.Modify an existing document or documents in collection. By default the method updates a single document. The query parameter employs the same query selectors, as used infind(DBObject)
.- Parameters:
query
- the selection criteria for the updateupdate
- the modifications to applyupsert
- when true, inserts a document if no document matches the update query criteriamulti
- when true, updates all documents in the collection that match the update query criteria, otherwise only updates oneconcern
-WriteConcern
to be used during operationbypassDocumentValidation
- whether to bypass document validation.encoder
- the DBEncoder to use- Returns:
- the result of the operation
- Throws:
DuplicateKeyException
- if the write failed to a duplicate unique keyWriteConcernException
- if the write failed due some other failure specific to the update commandMongoCommandException
- if the write failed due to a specific command exceptionMongoException
- if the operation failed for some other reason- Since:
- 2.14
-
update
public WriteResult update(DBObject query, DBObject update, boolean upsert, boolean multi)
Deprecated.Modify an existing document or documents in collection. The query parameter employs the same query selectors, as used infind()
.- Parameters:
query
- the selection criteria for the updateupdate
- the modifications to applyupsert
- when true, inserts a document if no document matches the update query criteriamulti
- when true, updates all documents in the collection that match the update query criteria, otherwise only updates one- Returns:
- the result of the operation
- Throws:
DuplicateKeyException
- if the write failed to a duplicate unique keyWriteConcernException
- if the write failed due some other failure specific to the update commandMongoCommandException
- if the write failed due to a specific command exceptionMongoException
- if the operation failed for some other reason
-
update
public WriteResult update(DBObject query, DBObject update)
Deprecated.Modify an existing document. The query parameter employs the same query selectors, as used infind()
.- Parameters:
query
- the selection criteria for the updateupdate
- the modifications to apply- Returns:
- the result of the operation
- Throws:
DuplicateKeyException
- if the write failed to a duplicate unique keyWriteConcernException
- if the write failed due some other failure specific to the update commandMongoCommandException
- if the write failed due to a specific command exceptionMongoException
- if the operation failed for some other reason
-
updateMulti
public WriteResult updateMulti(DBObject query, DBObject update)
Deprecated.Modify documents in collection. The query parameter employs the same query selectors, as used infind()
.- Parameters:
query
- the selection criteria for the updateupdate
- the modifications to apply- Returns:
- the result of the operation
- Throws:
DuplicateKeyException
- if the write failed to a duplicate unique keyWriteConcernException
- if the write failed due some other failure specific to the update commandMongoCommandException
- if the write failed due to a specific command exceptionMongoException
- if the operation failed for some other reason
-
update
public WriteResult update(DBObject query, DBObject update, DBCollectionUpdateOptions options)
Deprecated.Modify an existing document or documents in collection.- Parameters:
query
- the selection criteria for the updateupdate
- the modifications to applyoptions
- the options to apply to the update operation- Returns:
- the result of the operation
- Throws:
DuplicateKeyException
- if the write failed to a duplicate unique keyWriteConcernException
- if the write failed due some other failure specific to the update commandMongoCommandException
- if the write failed due to a specific command exceptionMongoException
- if the operation failed for some other reason- Since:
- 3.4
-
remove
public WriteResult remove(DBObject query)
Deprecated.Remove documents from a collection.- Parameters:
query
- the deletion criteria using query operators. Omit the query parameter or pass an empty document to delete all documents in the collection.- Returns:
- the result of the operation
- Throws:
WriteConcernException
- if the write failed due some other failure specific to the delete commandMongoCommandException
- if the write failed due to a specific command exceptionMongoException
- if the operation failed for some other reason
-
remove
public WriteResult remove(DBObject query, WriteConcern writeConcern)
Deprecated.Remove documents from a collection.- Parameters:
query
- the deletion criteria using query operators. Omit the query parameter or pass an empty document to delete all documents in the collection.writeConcern
-WriteConcern
to be used during operation- Returns:
- the result of the operation
- Throws:
WriteConcernException
- if the write failed due some other failure specific to the delete commandMongoCommandException
- if the write failed due to a specific command exceptionMongoException
- if the operation failed for some other reason
-
remove
public WriteResult remove(DBObject query, WriteConcern writeConcern, DBEncoder encoder)
Deprecated.Remove documents from a collection.- Parameters:
query
- the deletion criteria using query operators. Omit the query parameter or pass an empty document to delete all documents in the collection.writeConcern
-WriteConcern
to be used during operationencoder
-DBEncoder
to be used- Returns:
- the result of the operation
- Throws:
WriteConcernException
- if the write failed due some other failure specific to the delete commandMongoCommandException
- if the write failed due to a specific command exceptionMongoException
- if the operation failed for some other reason
-
remove
public WriteResult remove(DBObject query, DBCollectionRemoveOptions options)
Deprecated.Remove documents from a collection.- Parameters:
query
- the deletion criteria using query operators. Omit the query parameter or pass an empty document to delete all documents in the collection.options
- the options to apply to the delete operation- Returns:
- the result of the operation
- Throws:
WriteConcernException
- if the write failed due some other failure specific to the delete commandMongoCommandException
- if the write failed due to a specific command exceptionMongoException
- if the operation failed for some other reason- Since:
- 3.4
-
find
@Deprecated public DBCursor find(DBObject query, DBObject projection, int numToSkip, int batchSize, int options)
Deprecated.useDBCursor.skip(int)
,DBCursor.batchSize(int)
andDBCursor.setOptions(int)
on theDBCursor
returned fromfind(DBObject, DBObject)
Select documents in collection and get a cursor to the selected documents.- Parameters:
query
- the selection criteria using query operators. Omit the query parameter or pass an empty document to return all documents in the collection.projection
- specifies which fields MongoDB will return from the documents in the result set.numToSkip
- number of documents to skipbatchSize
- seeDBCursor.batchSize(int)
for more informationoptions
- query options to be used- Returns:
- A cursor to the documents that match the query criteria
-
find
@Deprecated public DBCursor find(DBObject query, DBObject projection, int numToSkip, int batchSize)
Deprecated.useDBCursor.skip(int)
andDBCursor.batchSize(int)
on theDBCursor
returned fromfind(DBObject, DBObject)
Select documents in collection and get a cursor to the selected documents.- Parameters:
query
- the selection criteria using query operators. Omit the query parameter or pass an empty document to return all documents in the collection.projection
- specifies which fields MongoDB will return from the documents in the result set.numToSkip
- number of documents to skipbatchSize
- seeDBCursor.batchSize(int)
for more information- Returns:
- A cursor to the documents that match the query criteria
-
find
public DBCursor find(DBObject query)
Deprecated.Select documents in collection and get a cursor to the selected documents.- Parameters:
query
- the selection criteria using query operators. Omit the query parameter or pass an empty document to return all documents in the collection.- Returns:
- A cursor to the documents that match the query criteria
-
find
public DBCursor find(DBObject query, DBObject projection)
Deprecated.Select documents in collection and get a cursor to the selected documents.- Parameters:
query
- the selection criteria using query operators. Omit the query parameter or pass an empty document to return all documents in the collection.projection
- specifies which fields MongoDB will return from the documents in the result set.- Returns:
- A cursor to the documents that match the query criteria
-
find
public DBCursor find()
Deprecated.Select all documents in collection and get a cursor to the selected documents.- Returns:
- A cursor to the documents that match the query criteria
-
find
public DBCursor find(@Nullable DBObject query, DBCollectionFindOptions options)
Deprecated.Select documents in collection and get a cursor to the selected documents.- Parameters:
query
- the selection criteria using query operators. Omit the query parameter or pass an empty document to return all documents in the collection.options
- the options for the find operation.- Returns:
- A cursor to the documents that match the query criteria
- Since:
- 3.4
-
findOne
@Nullable public DBObject findOne()
Deprecated.Get a single document from collection.- Returns:
- A document that satisfies the query specified as the argument to this method.
-
findOne
@Nullable public DBObject findOne(DBObject query)
Deprecated.Get a single document from collection.- Parameters:
query
- the selection criteria using query operators.- Returns:
- A document that satisfies the query specified as the argument to this method.
-
findOne
@Nullable public DBObject findOne(DBObject query, DBObject projection)
Deprecated.Get a single document from collection.- Parameters:
query
- the selection criteria using query operators.projection
- specifies which fields MongoDB will return from the documents in the result set.- Returns:
- A document that satisfies the query specified as the argument to this method.
-
findOne
@Nullable public DBObject findOne(DBObject query, DBObject projection, DBObject sort)
Deprecated.Get a single document from collection.- Parameters:
query
- the selection criteria using query operators.projection
- specifies which fields MongoDB will return from the documents in the result set.sort
- A document whose fields specify the attributes on which to sort the result set.- Returns:
- A document that satisfies the query specified as the argument to this method.
-
findOne
@Nullable public DBObject findOne(DBObject query, DBObject projection, ReadPreference readPreference)
Deprecated.Get a single document from collection.- Parameters:
query
- the selection criteria using query operators.projection
- specifies which fields MongoDB will return from the documents in the result set.readPreference
-ReadPreference
to be used for this operation- Returns:
- A document that satisfies the query specified as the argument to this method.
-
findOne
@Nullable public DBObject findOne(@Nullable DBObject query, @Nullable DBObject projection, @Nullable DBObject sort, ReadPreference readPreference)
Deprecated.Get a single document from collection.- Parameters:
query
- the selection criteria using query operators.projection
- specifies which projection MongoDB will return from the documents in the result set.sort
- A document whose fields specify the attributes on which to sort the result set.readPreference
-ReadPreference
to be used for this operation- Returns:
- A document that satisfies the query specified as the argument to this method.
-
findOne
@Nullable public DBObject findOne(java.lang.Object id)
Deprecated.Get a single document from collection by '_id'.- Parameters:
id
- value of '_id' field of a document we are looking for- Returns:
- A document with '_id' provided as the argument to this method.
-
findOne
@Nullable public DBObject findOne(java.lang.Object id, DBObject projection)
Deprecated.Get a single document from collection by '_id'.- Parameters:
id
- value of '_id' field of a document we are looking forprojection
- specifies which projection MongoDB will return from the documents in the result set.- Returns:
- A document that satisfies the query specified as the argument to this method.
-
findOne
@Nullable public DBObject findOne(@Nullable DBObject query, DBCollectionFindOptions findOptions)
Deprecated.Get a single document from collection.- Parameters:
query
- the selection criteria using query operators.findOptions
- the options for the find operation.- Returns:
- A document that satisfies the query specified as the argument to this method.
- Since:
- 3.4
-
count
public long count()
Deprecated.Same asgetCount()
- Returns:
- the number of documents in collection
- Throws:
MongoException
- if the operation failed
-
count
public long count(@Nullable DBObject query)
Deprecated.Same asgetCount(DBObject)
- Parameters:
query
- specifies the selection criteria- Returns:
- the number of documents that matches selection criteria
- Throws:
MongoException
- if the operation failed
-
count
public long count(@Nullable DBObject query, ReadPreference readPreference)
Deprecated.Get the count of documents in collection that would match a criteria.- Parameters:
query
- specifies the selection criteriareadPreference
-ReadPreference
to be used for this operation- Returns:
- the number of documents that matches selection criteria
- Throws:
MongoException
- if the operation failed
-
count
public long count(@Nullable DBObject query, DBCollectionCountOptions options)
Deprecated.Get the count of documents in collection that would match a criteria.- Parameters:
query
- specifies the selection criteriaoptions
- the options for the count operation.- Returns:
- the number of documents that matches selection criteria
- Throws:
MongoException
- if the operation failed- Since:
- 3.4
-
getCount
public long getCount()
Deprecated.Get the count of documents in collection.- Returns:
- the number of documents in collection
- Throws:
MongoException
- if the operation failed
-
getCount
public long getCount(ReadPreference readPreference)
Deprecated.Get the count of documents in collection.- Parameters:
readPreference
-ReadPreference
to be used for this operation- Returns:
- the number of documents in collection
- Throws:
MongoException
- if the operation failed
-
getCount
public long getCount(@Nullable DBObject query)
Deprecated.Get the count of documents in collection that would match a criteria.- Parameters:
query
- specifies the selection criteria- Returns:
- the number of documents that matches selection criteria
- Throws:
MongoException
- if the operation failed
-
getCount
@Deprecated public long getCount(@Nullable DBObject query, DBObject projection)
Deprecated.Get the count of documents in collection that would match a criteria.- Parameters:
query
- specifies the selection criteriaprojection
- this is ignored- Returns:
- the number of documents that matches selection criteria
- Throws:
MongoException
- if the operation failed
-
getCount
@Deprecated public long getCount(@Nullable DBObject query, @Nullable DBObject projection, ReadPreference readPreference)
Deprecated.Get the count of documents in collection that would match a criteria.- Parameters:
query
- specifies the selection criteriaprojection
- this is ignoredreadPreference
-ReadPreference
to be used for this operation- Returns:
- the number of documents that matches selection criteria
- Throws:
MongoException
- if the operation failed
-
getCount
@Deprecated public long getCount(@Nullable DBObject query, @Nullable DBObject projection, long limit, long skip)
Deprecated.Get the count of documents in collection that would match a criteria.- Parameters:
query
- specifies the selection criteriaprojection
- this is ignoredlimit
- limit the count to this valueskip
- number of documents to skip- Returns:
- the number of documents that matches selection criteria
- Throws:
MongoException
- if the operation failed
-
getCount
@Deprecated public long getCount(@Nullable DBObject query, @Nullable DBObject projection, long limit, long skip, ReadPreference readPreference)
Deprecated.Get the count of documents in collection that would match a criteria.- Parameters:
query
- specifies the selection criteriaprojection
- this is ignoredlimit
- limit the count to this valueskip
- number of documents to skipreadPreference
-ReadPreference
to be used for this operation- Returns:
- the number of documents that matches selection criteria
- Throws:
MongoException
- if the operation failed
-
getCount
public long getCount(@Nullable DBObject query, DBCollectionCountOptions options)
Deprecated.Get the count of documents in collection that would match a criteria.- Parameters:
query
- specifies the selection criteriaoptions
- the options for the count operation.- Returns:
- the number of documents that matches selection criteria
- Throws:
MongoException
- if the operation failed- Since:
- 3.4
-
rename
public DBCollection rename(java.lang.String newName)
Deprecated.Change the name of an existing collection.- Parameters:
newName
- specifies the new name of the collection- Returns:
- the collection with new name
- Throws:
MongoException
- if newName is the name of an existing collection.
-
rename
public DBCollection rename(java.lang.String newName, boolean dropTarget)
Deprecated.Change the name of an existing collection.- Parameters:
newName
- specifies the new name of the collectiondropTarget
- Iftrue
, mongod will drop the collection with the target name if it exists- Returns:
- the collection with new name
- Throws:
MongoException
- if target is the name of an existing collection anddropTarget=false
.
-
group
@Deprecated public DBObject group(DBObject key, DBObject cond, DBObject initial, java.lang.String reduce)
Deprecated.The group command was deprecated in MongoDB 3.4Group documents in a collection by the specified key and performs simple aggregation functions such as computing counts and sums. This is analogous to aSELECT ... GROUP BY
statement in SQL.- Parameters:
key
- specifies one or more document fields to groupcond
- specifies the selection criteria to determine which documents in the collection to processinitial
- initializes the aggregation result documentreduce
- specifies an $reduce function, that operates on the documents during the grouping operation- Returns:
- a document with the grouped records as well as the command meta-data
-
group
@Deprecated public DBObject group(DBObject key, DBObject cond, DBObject initial, java.lang.String reduce, @Nullable java.lang.String finalize)
Deprecated.The group command was deprecated in MongoDB 3.4Group documents in a collection by the specified key and performs simple aggregation functions such as computing counts and sums. This is analogous to aSELECT ... GROUP BY
statement in SQL.- Parameters:
key
- specifies one or more document fields to groupcond
- specifies the selection criteria to determine which documents in the collection to processinitial
- initializes the aggregation result documentreduce
- specifies an $reduce Javascript function, that operates on the documents during the grouping operationfinalize
- specifies a Javascript function that runs each item in the result set before final value will be returned- Returns:
- a document with the grouped records as well as the command meta-data
-
group
@Deprecated public DBObject group(DBObject key, DBObject cond, DBObject initial, java.lang.String reduce, @Nullable java.lang.String finalize, ReadPreference readPreference)
Deprecated.The group command was deprecated in MongoDB 3.4Group documents in a collection by the specified key and performs simple aggregation functions such as computing counts and sums. This is analogous to aSELECT ... GROUP BY
statement in SQL.- Parameters:
key
- specifies one or more document fields to groupcond
- specifies the selection criteria to determine which documents in the collection to processinitial
- initializes the aggregation result documentreduce
- specifies an $reduce Javascript function, that operates on the documents during the grouping operationfinalize
- specifies a Javascript function that runs each item in the result set before final value will be returnedreadPreference
-ReadPreference
to be used for this operation- Returns:
- a document with the grouped records as well as the command meta-data
-
group
@Deprecated public DBObject group(GroupCommand cmd)
Deprecated.The group command was deprecated in MongoDB 3.4Group documents in a collection by the specified key and performs simple aggregation functions such as computing counts and sums. This is analogous to aSELECT ... GROUP BY
statement in SQL.- Parameters:
cmd
- the group command- Returns:
- a document with the grouped records as well as the command meta-data
-
group
@Deprecated public DBObject group(GroupCommand cmd, ReadPreference readPreference)
Deprecated.The group command was deprecated in MongoDB 3.4Group documents in a collection by the specified key and performs simple aggregation functions such as computing counts and sums. This is analogous to aSELECT ... GROUP BY
statement in SQL.- Parameters:
cmd
- the group commandreadPreference
-ReadPreference
to be used for this operation- Returns:
- a document with the grouped records as well as the command meta-data
-
distinct
public java.util.List distinct(java.lang.String fieldName)
Deprecated.Find the distinct values for a specified field across a collection and returns the results in an array.- Parameters:
fieldName
- Specifies the field for which to return the distinct values.- Returns:
- a List of the distinct values
-
distinct
public java.util.List distinct(java.lang.String fieldName, ReadPreference readPreference)
Deprecated.Find the distinct values for a specified field across a collection and returns the results in an array.- Parameters:
fieldName
- Specifies the field for which to return the distinct valuesreadPreference
-ReadPreference
to be used for this operation- Returns:
- a List of the distinct values
-
distinct
public java.util.List distinct(java.lang.String fieldName, DBObject query)
Deprecated.Find the distinct values for a specified field across a collection and returns the results in an array.- Parameters:
fieldName
- Specifies the field for which to return the distinct valuesquery
- specifies the selection query to determine the subset of documents from which to retrieve the distinct values- Returns:
- an array of the distinct values
-
distinct
public java.util.List distinct(java.lang.String fieldName, DBObject query, ReadPreference readPreference)
Deprecated.Find the distinct values for a specified field across a collection and returns the results in an array.- Parameters:
fieldName
- Specifies the field for which to return the distinct valuesquery
- specifies the selection query to determine the subset of documents from which to retrieve the distinct valuesreadPreference
-ReadPreference
to be used for this operation- Returns:
- A
List
of the distinct values
-
distinct
public java.util.List distinct(java.lang.String fieldName, DBCollectionDistinctOptions options)
Deprecated.Find the distinct values for a specified field across a collection and returns the results in an array.- Parameters:
fieldName
- Specifies the field for which to return the distinct valuesoptions
- the options to apply for this operation- Returns:
- A
List
of the distinct values - Since:
- 3.4
-
mapReduce
public MapReduceOutput mapReduce(java.lang.String map, java.lang.String reduce, java.lang.String outputTarget, DBObject query)
Deprecated.Allows you to run map-reduce aggregation operations over a collection.- Parameters:
map
- a JavaScript function that associates or "maps" a value with a key and emits the key and value pair.reduce
- a JavaScript function that "reduces" to a single object all the values associated with a particular key.outputTarget
- specifies the location of the result of the map-reduce operation.query
- specifies the selection criteria using query operators for determining the documents input to the map function.- Returns:
- a MapReduceOutput which contains the results of this map reduce operation
-
mapReduce
public MapReduceOutput mapReduce(java.lang.String map, java.lang.String reduce, java.lang.String outputTarget, MapReduceCommand.OutputType outputType, DBObject query)
Deprecated.Allows you to run map-reduce aggregation operations over a collection and saves to a named collection.- Parameters:
map
- a JavaScript function that associates or "maps" a value with a key and emits the key and value pair.reduce
- a JavaScript function that "reduces" to a single object all the values associated with a particular key.outputTarget
- specifies the location of the result of the map-reduce operation.outputType
- specifies the type of job outputquery
- specifies the selection criteria using query operators for determining the documents input to the map function.- Returns:
- a MapReduceOutput which contains the results of this map reduce operation
-
mapReduce
public MapReduceOutput mapReduce(java.lang.String map, java.lang.String reduce, java.lang.String outputTarget, MapReduceCommand.OutputType outputType, DBObject query, ReadPreference readPreference)
Deprecated.Allows you to run map-reduce aggregation operations over a collection and saves to a named collection.- Parameters:
map
- a JavaScript function that associates or "maps" a value with a key and emits the key and value pair.reduce
- a JavaScript function that "reduces" to a single object all the values associated with a particular key.outputTarget
- specifies the location of the result of the map-reduce operation.outputType
- specifies the type of job outputquery
- specifies the selection criteria using query operators for determining the documents input to the map function.readPreference
- the read preference specifying where to run the query. Only applied for Inline output type- Returns:
- a MapReduceOutput which contains the results of this map reduce operation
-
mapReduce
public MapReduceOutput mapReduce(MapReduceCommand command)
Deprecated.Allows you to run map-reduce aggregation operations over a collection.- Parameters:
command
- specifies the details of the Map Reduce operation to perform- Returns:
- a MapReduceOutput containing the results of the map reduce operation
-
aggregate
@Deprecated public AggregationOutput aggregate(DBObject firstOp, DBObject... additionalOps)
Deprecated.Useaggregate(List, AggregationOptions)
insteadMethod implements aggregation framework.- Parameters:
firstOp
- requisite first operation to be performed in the aggregation pipelineadditionalOps
- additional operations to be performed in the aggregation pipeline- Returns:
- the aggregation operation's result set
-
aggregate
@Deprecated public AggregationOutput aggregate(java.util.List<? extends DBObject> pipeline)
Deprecated.Useaggregate(List, AggregationOptions)
insteadMethod implements aggregation framework.- Parameters:
pipeline
- operations to be performed in the aggregation pipeline- Returns:
- the aggregation's result set
-
aggregate
@Deprecated public AggregationOutput aggregate(java.util.List<? extends DBObject> pipeline, ReadPreference readPreference)
Deprecated.Useaggregate(List, AggregationOptions, ReadPreference)
)} insteadMethod implements aggregation framework.- Parameters:
pipeline
- operations to be performed in the aggregation pipelinereadPreference
- the read preference specifying where to run the query- Returns:
- the aggregation's result set
-
aggregate
public Cursor aggregate(java.util.List<? extends DBObject> pipeline, AggregationOptions options)
Deprecated.Method implements aggregation framework.- Parameters:
pipeline
- operations to be performed in the aggregation pipelineoptions
- options to apply to the aggregation- Returns:
- the aggregation operation's result set
-
aggregate
public Cursor aggregate(java.util.List<? extends DBObject> pipeline, AggregationOptions options, ReadPreference readPreference)
Deprecated.Method implements aggregation framework.- Parameters:
pipeline
- operations to be performed in the aggregation pipelineoptions
- options to apply to the aggregationreadPreference
-ReadPreference
to be used for this operation- Returns:
- the aggregation operation's result set
-
explainAggregate
public CommandResult explainAggregate(java.util.List<? extends DBObject> pipeline, AggregationOptions options)
Deprecated.Return the explain plan for the aggregation pipeline.- Parameters:
pipeline
- the aggregation pipeline to explainoptions
- the options to apply to the aggregation- Returns:
- the command result. The explain output may change from release to release, so best to simply log this.
-
parallelScan
@Deprecated public java.util.List<Cursor> parallelScan(ParallelScanOptions options)
Deprecated.the parallelCollectionScan command will be removed in MongoDB 4.2Return a list of cursors over the collection that can be used to scan it in parallel.
Note: As of MongoDB 2.6, this method will work against a mongod, but not a mongos.
- Parameters:
options
- the parallel scan options- Returns:
- a list of cursors, whose size may be less than the number requested
- Since:
- 2.12
-
getName
public java.lang.String getName()
Deprecated.Get the name of a collection.- Returns:
- the name of a collection
-
getFullName
public java.lang.String getFullName()
Deprecated.Get the full name of a collection, with the database name as a prefix.- Returns:
- the name of a collection
-
getCollection
public DBCollection getCollection(java.lang.String name)
Deprecated.Find a collection that is prefixed with this collection's name. A typical use of this might be
Which is equivalent toDBCollection users = mongo.getCollection( "wiki" ).getCollection( "users" );
DBCollection users = mongo.getCollection( "wiki.users" );
- Parameters:
name
- the name of the collection to find- Returns:
- the matching collection
-
createIndex
public void createIndex(java.lang.String name)
Deprecated.Forces creation of an ascending index on a field with the default options.- Parameters:
name
- name of field to index on- Throws:
MongoException
- if the operation failed
-
createIndex
public void createIndex(DBObject keys, java.lang.String name)
Deprecated.Forces creation of an index on a set of fields, if one does not already exist.- Parameters:
keys
- a document that contains pairs with the name of the field or fields to index and order of the indexname
- an identifier for the index. If null or empty, the default name will be used.- Throws:
MongoException
- if the operation failed
-
createIndex
public void createIndex(DBObject keys, @Nullable java.lang.String name, boolean unique)
Deprecated.Forces creation of an index on a set of fields, if one does not already exist.- Parameters:
keys
- a document that contains pairs with the name of the field or fields to index and order of the indexname
- an identifier for the index. If null or empty, the default name will be used.unique
- if the index should be unique- Throws:
MongoException
- if the operation failed
-
createIndex
public void createIndex(DBObject keys)
Deprecated.Creates an index on the field specified, if that index does not already exist.- Parameters:
keys
- a document that contains pairs with the name of the field or fields to index and order of the index
-
createIndex
public void createIndex(DBObject keys, DBObject options)
Deprecated.Creates an index on the field specified, if that index does not already exist.Prior to MongoDB 3.0 the dropDups option could be used with unique indexes allowing documents with duplicate values to be dropped when building the index. Later versions of MongoDB will silently ignore this setting.
- Parameters:
keys
- a document that contains pairs with the name of the field or fields to index and order of the indexoptions
- a document that controls the creation of the index.
-
getHintFields
@Deprecated @Nullable public java.util.List<DBObject> getHintFields()
Deprecated.PreferDBCursor.hint(DBObject)
Get hint fields for this collection (used to optimize queries).- Returns:
- a list of
DBObject
to be used as hints.
-
setHintFields
@Deprecated public void setHintFields(java.util.List<? extends DBObject> indexes)
Deprecated.PreferDBCursor.hint(DBObject)
Override MongoDB's default index selection and query optimization process.- Parameters:
indexes
- list of indexes to "hint" or force MongoDB to use when performing the query.
-
findAndModify
@Nullable public DBObject findAndModify(@Nullable DBObject query, @Nullable DBObject sort, DBObject update)
Deprecated.Atomically modify and return a single document. By default, the returned document does not include the modifications made on the update.- Parameters:
query
- specifies the selection criteria for the modificationsort
- determines which document the operation will modify if the query selects multiple documentsupdate
- the modifications to apply- Returns:
- pre-modification document
- Throws:
WriteConcernException
- if the write failed due some other failure specific to the update commandMongoCommandException
- if the write failed due to a specific command exceptionMongoException
- if the operation failed for some other reason
-
findAndModify
@Nullable public DBObject findAndModify(@Nullable DBObject query, DBObject update)
Deprecated.Atomically modify and return a single document. By default, the returned document does not include the modifications made on the update.- Parameters:
query
- specifies the selection criteria for the modificationupdate
- the modifications to apply- Returns:
- the document as it was before the modifications
- Throws:
WriteConcernException
- if the write failed due some other failure specific to the update commandMongoCommandException
- if the write failed due to a specific command exceptionMongoException
- if the operation failed for some other reason
-
findAndRemove
@Nullable public DBObject findAndRemove(@Nullable DBObject query)
Deprecated.Atomically remove and return a single document. The returned document is the original document before removal.- Parameters:
query
- specifies the selection criteria for the modification- Returns:
- the document as it was before the modifications
- Throws:
WriteConcernException
- if the write failed due some other failure specific to the update commandMongoCommandException
- if the write failed due to a specific command exceptionMongoException
- if the operation failed for some other reason
-
findAndModify
@Nullable public DBObject findAndModify(@Nullable DBObject query, @Nullable DBObject fields, @Nullable DBObject sort, boolean remove, @Nullable DBObject update, boolean returnNew, boolean upsert)
Deprecated.Atomically modify and return a single document. By default, the returned document does not include the modifications made on the update.- Parameters:
query
- specifies the selection criteria for the modificationfields
- a subset of fields to returnsort
- determines which document the operation will modify if the query selects multiple documentsremove
- whentrue
, removes the selected documentreturnNew
- when true, returns the modified document rather than the originalupdate
- the modifications to applyupsert
- when true, operation creates a new document if the query returns no documents- Returns:
- the document as it was before the modifications, unless
returnNew
is true, in which case it returns the document after the changes were made - Throws:
WriteConcernException
- if the write failed due some other failure specific to the update commandMongoCommandException
- if the write failed due to a specific command exceptionMongoException
- if the operation failed for some other reason
-
findAndModify
@Nullable public DBObject findAndModify(@Nullable DBObject query, @Nullable DBObject fields, @Nullable DBObject sort, boolean remove, DBObject update, boolean returnNew, boolean upsert, WriteConcern writeConcern)
Deprecated.Atomically modify and return a single document. By default, the returned document does not include the modifications made on the update.- Parameters:
query
- specifies the selection criteria for the modificationfields
- a subset of fields to returnsort
- determines which document the operation will modify if the query selects multiple documentsremove
- when true, removes the selected documentreturnNew
- when true, returns the modified document rather than the originalupdate
- the modifications to applyupsert
- when true, operation creates a new document if the query returns no documentswriteConcern
- the write concern to apply to this operation- Returns:
- the document as it was before the modifications, unless
returnNew
is true, in which case it returns the document after the changes were made - Throws:
WriteConcernException
- if the write failed due some other failure specific to the update commandMongoCommandException
- if the write failed due to a specific command exceptionMongoException
- if the operation failed for some other reason- Since:
- 2.14
-
findAndModify
@Nullable public DBObject findAndModify(@Nullable DBObject query, @Nullable DBObject fields, @Nullable DBObject sort, boolean remove, @Nullable DBObject update, boolean returnNew, boolean upsert, long maxTime, java.util.concurrent.TimeUnit maxTimeUnit)
Deprecated.Atomically modify and return a single document. By default, the returned document does not include the modifications made on the update.- Parameters:
query
- specifies the selection criteria for the modificationfields
- a subset of fields to returnsort
- determines which document the operation will modify if the query selects multiple documentsremove
- when true, removes the selected documentreturnNew
- when true, returns the modified document rather than the originalupdate
- the modifications to applyupsert
- when true, operation creates a new document if the query returns no documentsmaxTime
- the maximum time that the server will allow this operation to execute before killing it. A non-zero value requires a server version >= 2.6maxTimeUnit
- the unit that maxTime is specified in- Returns:
- the document as it was before the modifications, unless
returnNew
is true, in which case it returns the document after the changes were made - Throws:
WriteConcernException
- if the write failed due some other failure specific to the update commandMongoCommandException
- if the write failed due to a specific command exceptionMongoException
- if the operation failed for some other reason- Since:
- 2.12.0
-
findAndModify
@Nullable public DBObject findAndModify(@Nullable DBObject query, @Nullable DBObject fields, @Nullable DBObject sort, boolean remove, @Nullable DBObject update, boolean returnNew, boolean upsert, long maxTime, java.util.concurrent.TimeUnit maxTimeUnit, WriteConcern writeConcern)
Deprecated.Atomically modify and return a single document. By default, the returned document does not include the modifications made on the update.- Parameters:
query
- specifies the selection criteria for the modificationfields
- a subset of fields to returnsort
- determines which document the operation will modify if the query selects multiple documentsremove
- whentrue
, removes the selected documentreturnNew
- when true, returns the modified document rather than the originalupdate
- performs an update of the selected documentupsert
- when true, operation creates a new document if the query returns no documentsmaxTime
- the maximum time that the server will allow this operation to execute before killing it. A non-zero value requires a server version >= 2.6maxTimeUnit
- the unit that maxTime is specified inwriteConcern
- the write concern to apply to this operation- Returns:
- the document as it was before the modifications, unless
returnNew
is true, in which case it returns the document after the changes were made - Throws:
WriteConcernException
- if the write failed due some other failure specific to the update commandMongoCommandException
- if the write failed due to a specific command exceptionMongoException
- if the operation failed for some other reason- Since:
- 2.14.0
-
findAndModify
@Nullable public DBObject findAndModify(DBObject query, DBObject fields, DBObject sort, boolean remove, @Nullable DBObject update, boolean returnNew, boolean upsert, boolean bypassDocumentValidation, long maxTime, java.util.concurrent.TimeUnit maxTimeUnit)
Deprecated.Atomically modify and return a single document. By default, the returned document does not include the modifications made on the update.- Parameters:
query
- specifies the selection criteria for the modificationfields
- a subset of fields to returnsort
- determines which document the operation will modify if the query selects multiple documentsremove
- whentrue
, removes the selected documentreturnNew
- when true, returns the modified document rather than the originalupdate
- performs an update of the selected documentupsert
- when true, operation creates a new document if the query returns no documentsbypassDocumentValidation
- whether to bypass document validation.maxTime
- the maximum time that the server will allow this operation to execute before killing it. A non-zero value requires a server version >= 2.6maxTimeUnit
- the unit that maxTime is specified in- Returns:
- the document as it was before the modifications, unless
returnNew
is true, in which case it returns the document after the changes were made - Throws:
WriteConcernException
- if the write failed due some other failure specific to the update commandMongoCommandException
- if the write failed due to a specific command exceptionMongoException
- if the operation failed for some other reason- Since:
- 2.14.0
-
findAndModify
public DBObject findAndModify(@Nullable DBObject query, @Nullable DBObject fields, @Nullable DBObject sort, boolean remove, @Nullable DBObject update, boolean returnNew, boolean upsert, boolean bypassDocumentValidation, long maxTime, java.util.concurrent.TimeUnit maxTimeUnit, WriteConcern writeConcern)
Deprecated.Atomically modify and return a single document. By default, the returned document does not include the modifications made on the update.- Parameters:
query
- specifies the selection criteria for the modificationfields
- a subset of fields to returnsort
- determines which document the operation will modify if the query selects multiple documentsremove
- whentrue
, removes the selected documentreturnNew
- when true, returns the modified document rather than the originalupdate
- performs an update of the selected documentupsert
- when true, operation creates a new document if the query returns no documentsbypassDocumentValidation
- whether to bypass document validation.maxTime
- the maximum time that the server will allow this operation to execute before killing it. A non-zero value requires a server version >= 2.6maxTimeUnit
- the unit that maxTime is specified inwriteConcern
- the write concern to apply to this operation- Returns:
- the document as it was before the modifications, unless
returnNew
is true, in which case it returns the document after the changes were made - Throws:
WriteConcernException
- if the write failed due some other failure specific to the update commandMongoCommandException
- if the write failed due to a specific command exceptionMongoException
- if the operation failed for some other reason- Since:
- 2.14.0
-
findAndModify
public DBObject findAndModify(DBObject query, DBCollectionFindAndModifyOptions options)
Deprecated.Atomically modify and return a single document. By default, the returned document does not include the modifications made on the update.- Parameters:
query
- specifies the selection criteria for the modificationoptions
- the options regarding the find and modify operation- Returns:
- the document as it was before the modifications, unless
oprtions.returnNew
is true, in which case it returns the document after the changes were made - Throws:
WriteConcernException
- if the write failed due some other failure specific to the update commandMongoCommandException
- if the write failed due to a specific command exceptionMongoException
- if the operation failed for some other reason- Since:
- 3.4
-
getDB
public DB getDB()
Deprecated.Returns the database this collection is a member of.- Returns:
- this collection's database
-
getWriteConcern
public WriteConcern getWriteConcern()
Deprecated.Get theWriteConcern
for this collection.- Returns:
- the default write concern for this collection
-
setWriteConcern
public void setWriteConcern(WriteConcern writeConcern)
Deprecated.Set theWriteConcern
for this collection. Will be used for writes to this collection. Overrides any setting of write concern at the DB level.- Parameters:
writeConcern
- WriteConcern to use
-
getReadPreference
public ReadPreference getReadPreference()
Deprecated.Gets theReadPreference
.- Returns:
- the default read preference for this collection
-
setReadPreference
public void setReadPreference(ReadPreference preference)
Deprecated.Sets theReadPreference
for this collection. Will be used as default for reads from this collection; overrides DB and Connection level settings. See the documentation forReadPreference
for more information.- Parameters:
preference
- ReadPreference to use
-
setReadConcern
public void setReadConcern(ReadConcern readConcern)
Deprecated.Sets the read concern for this collection.- Parameters:
readConcern
- the read concern to use for this collection- Since:
- 3.3
-
getReadConcern
public ReadConcern getReadConcern()
Deprecated.Get the read concern for this collection.- Returns:
- the
ReadConcern
- Since:
- 3.3
-
slaveOk
@Deprecated public void slaveOk()
Deprecated.Replaced withReadPreference.secondaryPreferred()
Makes this query ok to run on a slave node
-
addOption
@Deprecated public void addOption(int option)
Deprecated.Replaced withDBCursor.addOption(int)
Adds the given flag to the default query options.- Parameters:
option
- value to be added
-
resetOptions
@Deprecated public void resetOptions()
Deprecated.Replaced withDBCursor.resetOptions()
Resets the default query options
-
getOptions
@Deprecated public int getOptions()
Deprecated.Replaced withDBCursor.getOptions()
Gets the default query options- Returns:
- bit vector of query options
-
setOptions
@Deprecated public void setOptions(int options)
Deprecated.Replaced withDBCursor.setOptions(int)
Sets the default query options, overwriting previous value.- Parameters:
options
- bit vector of query options
-
drop
public void drop()
Deprecated.Drops (deletes) this collection from the database. Use with care.- Throws:
MongoCommandException
- if the write failed due to a specific command exceptionMongoException
- if the operation failed
-
getDBDecoderFactory
public DBDecoderFactory getDBDecoderFactory()
Deprecated.Get the decoder factory for this collection. A null return value means that the default from MongoOptions is being used.- Returns:
- the factory
-
setDBDecoderFactory
public void setDBDecoderFactory(@Nullable DBDecoderFactory factory)
Deprecated.Set a custom decoder factory for this collection. Set to null to use the default from MongoOptions.- Parameters:
factory
- the factory to set.
-
getDBEncoderFactory
public DBEncoderFactory getDBEncoderFactory()
Deprecated.Get the encoder factory for this collection. A null return value means that the default from MongoOptions is being used.- Returns:
- the factory
-
setDBEncoderFactory
public void setDBEncoderFactory(@Nullable DBEncoderFactory factory)
Deprecated.Set a custom encoder factory for this collection. Set to null to use the default from MongoOptions.- Parameters:
factory
- the factory to set.
-
getIndexInfo
public java.util.List<DBObject> getIndexInfo()
Deprecated.Return a list of the indexes for this collection. Each object in the list is the "info document" from MongoDB- Returns:
- list of index documents
- Throws:
MongoException
- if the operation failed
-
dropIndex
public void dropIndex(DBObject index)
Deprecated.Drops an index from this collection. The DBObject index parameter must match the specification of the index to drop, i.e. correct key name and type must be specified.- Parameters:
index
- the specification of the index to drop- Throws:
MongoException
- if the index does not exist
-
dropIndex
public void dropIndex(java.lang.String indexName)
Deprecated.Drops the index with the given name from this collection.- Parameters:
indexName
- name of index to drop- Throws:
MongoException
- if the index does not exist
-
dropIndexes
public void dropIndexes()
Deprecated.Drop all indexes on this collection. The default index on the _id field will not be deleted.
-
dropIndexes
public void dropIndexes(java.lang.String indexName)
Deprecated.Drops the index with the given name from this collection. This method is exactly the same asdropIndex(indexName)
.- Parameters:
indexName
- name of index to drop- Throws:
MongoException
- if the index does not exist
-
getStats
public CommandResult getStats()
Deprecated.The collStats command returns a variety of storage statistics for a given collection- Returns:
- a CommandResult containing the statistics about this collection
-
isCapped
public boolean isCapped()
Deprecated.Checks whether this collection is capped- Returns:
- true if this is a capped collection
-
getObjectClass
public java.lang.Class getObjectClass()
Deprecated.Gets the default class for objects in the collection- Returns:
- the class
-
setObjectClass
public void setObjectClass(java.lang.Class<? extends DBObject> aClass)
Deprecated.Sets a default class for objects in this collection; null resets the class to nothing.- Parameters:
aClass
- the class
-
setInternalClass
public void setInternalClass(java.lang.String path, java.lang.Class<? extends DBObject> aClass)
Deprecated.Sets the internal class for the given path in the document hierarchy- Parameters:
path
- the path to map the given Class toaClass
- the Class to map the given path to
-
toString
public java.lang.String toString()
Deprecated.- Overrides:
toString
in classjava.lang.Object
-
initializeOrderedBulkOperation
public BulkWriteOperation initializeOrderedBulkOperation()
Deprecated.Creates a builder for an ordered bulk write operation, consisting of an ordered collection of write requests, which can be any combination of inserts, updates, replaces, or removes. Write requests included in the bulk operations will be executed in order, and will halt on the first failure.
Note: While this bulk write operation will execute on MongoDB 2.4 servers and below, the writes will be performed one at a time, as that is the only way to preserve the semantics of the value returned from execution or the exception thrown.
Note: While a bulk write operation with a mix of inserts, updates, replaces, and removes is supported, the implementation will batch up consecutive requests of the same type and send them to the server one at a time. For example, if a bulk write operation consists of 10 inserts followed by 5 updates, followed by 10 more inserts, it will result in three round trips to the server.
- Returns:
- the builder
- Since:
- 2.12
-
initializeUnorderedBulkOperation
public BulkWriteOperation initializeUnorderedBulkOperation()
Deprecated.Creates a builder for an unordered bulk operation, consisting of an unordered collection of write requests, which can be any combination of inserts, updates, replaces, or removes. Write requests included in the bulk operation will be executed in an undefined order, and all requests will be executed even if some fail.
Note: While this bulk write operation will execute on MongoDB 2.4 servers and below, the writes will be performed one at a time, as that is the only way to preserve the semantics of the value returned from execution or the exception thrown.
- Returns:
- the builder
- Since:
- 2.12
-
-