DocumentT - The type that this collection will encode documents from and decode documents
to.public class MongoCollection<DocumentT> extends Object
Use MongoDatabase.getCollection(java.lang.String) to get a collection instance.
Before any access is possible, there must be an active, logged-in user.
MongoDatabase| Modifier and Type | Method and Description |
|---|---|
AggregateIterable<DocumentT> |
aggregate(List<? extends Bson> pipeline)
Aggregates documents according to the specified aggregation pipeline.
|
<ResultT> AggregateIterable<ResultT> |
aggregate(List<? extends Bson> pipeline,
Class<ResultT> resultClass)
Aggregates documents according to the specified aggregation pipeline specifying an output
class.
|
RealmResultTask<Long> |
count()
Counts the number of documents in the collection.
|
RealmResultTask<Long> |
count(Bson filter)
Counts the number of documents in the collection according to the given options.
|
RealmResultTask<Long> |
count(Bson filter,
CountOptions options)
Counts the number of documents in the collection according to the given options.
|
RealmResultTask<DeleteResult> |
deleteMany(Bson filter)
Removes all documents from the collection that match the given query filter.
|
RealmResultTask<DeleteResult> |
deleteOne(Bson filter)
Removes at most one document from the collection that matches the given filter.
|
FindIterable<DocumentT> |
find()
Finds all documents in the collection.
|
FindIterable<DocumentT> |
find(Bson filter)
Finds all documents in the collection that match the given filter.
|
<ResultT> FindIterable<ResultT> |
find(Bson filter,
Class<ResultT> resultClass)
Finds all documents in the collection that match the given filter specifying an output class.
|
<ResultT> FindIterable<ResultT> |
find(Bson filter,
Class<ResultT> resultClass,
FindOptions options)
Finds all documents in the collection that match the given filter specifying an output class
and also using
FindOptions to build the query. |
FindIterable<DocumentT> |
find(Bson filter,
FindOptions options)
Finds all documents in the collection that match the given filter using
FindOptions
to build the query. |
<ResultT> FindIterable<ResultT> |
find(Class<ResultT> resultClass)
Finds all documents in the collection specifying an output class.
|
<ResultT> FindIterable<ResultT> |
find(Class<ResultT> resultClass,
FindOptions options)
Finds all documents in the collection specifying an output class and also using
FindOptions to build the query. |
FindIterable<DocumentT> |
find(FindOptions options)
Finds all documents in the collection using
FindOptions to build the query. |
RealmResultTask<DocumentT> |
findOne()
Finds a document in the collection.
|
RealmResultTask<DocumentT> |
findOne(Bson filter)
Finds a document in the collection.
|
<ResultT> RealmResultTask<ResultT> |
findOne(Bson filter,
Class<ResultT> resultClass)
Finds a document in the collection.
|
RealmResultTask<DocumentT> |
findOne(Bson filter,
FindOptions options)
Finds a document in the collection.
|
<ResultT> RealmResultTask<ResultT> |
findOne(Bson filter,
FindOptions options,
Class<ResultT> resultClass)
Finds a document in the collection.
|
<ResultT> RealmResultTask<ResultT> |
findOne(Class<ResultT> resultClass)
Finds a document in the collection.
|
RealmResultTask<DocumentT> |
findOneAndDelete(Bson filter)
Finds a document in the collection and delete it.
|
<ResultT> RealmResultTask<ResultT> |
findOneAndDelete(Bson filter,
Class<ResultT> resultClass)
Finds a document in the collection and delete it.
|
RealmResultTask<DocumentT> |
findOneAndDelete(Bson filter,
FindOneAndModifyOptions options)
Finds a document in the collection and delete it.
|
<ResultT> RealmResultTask<ResultT> |
findOneAndDelete(Bson filter,
FindOneAndModifyOptions options,
Class<ResultT> resultClass)
Finds a document in the collection and delete it.
|
RealmResultTask<DocumentT> |
findOneAndReplace(Bson filter,
Bson replacement)
Finds a document in the collection and replaces it with the given document.
|
<ResultT> RealmResultTask<ResultT> |
findOneAndReplace(Bson filter,
Bson replacement,
Class<ResultT> resultClass)
Finds a document in the collection and replaces it with the given document.
|
RealmResultTask<DocumentT> |
findOneAndReplace(Bson filter,
Bson replacement,
FindOneAndModifyOptions options)
Finds a document in the collection and replaces it with the given document.
|
<ResultT> RealmResultTask<ResultT> |
findOneAndReplace(Bson filter,
Bson replacement,
FindOneAndModifyOptions options,
Class<ResultT> resultClass)
Finds a document in the collection and replaces it with the given document.
|
RealmResultTask<DocumentT> |
findOneAndUpdate(Bson filter,
Bson update)
Finds a document in the collection and performs the given update.
|
<ResultT> RealmResultTask<ResultT> |
findOneAndUpdate(Bson filter,
Bson update,
Class<ResultT> resultClass)
Finds a document in the collection and performs the given update.
|
RealmResultTask<DocumentT> |
findOneAndUpdate(Bson filter,
Bson update,
FindOneAndModifyOptions options)
Finds a document in the collection and performs the given update.
|
<ResultT> RealmResultTask<ResultT> |
findOneAndUpdate(Bson filter,
Bson update,
FindOneAndModifyOptions options,
Class<ResultT> resultClass)
Finds a document in the collection and performs the given update.
|
CodecRegistry |
getCodecRegistry()
Gets the codec registry for the MongoCollection.
|
Class<DocumentT> |
getDocumentClass()
Gets the class of documents stored in this collection.
|
String |
getName()
Gets the name of this collection
|
MongoNamespace |
getNamespace()
Gets the namespace of this collection, i.e.
|
RealmResultTask<InsertManyResult> |
insertMany(List<? extends DocumentT> documents)
Inserts one or more documents.
|
RealmResultTask<InsertOneResult> |
insertOne(DocumentT document)
Inserts the provided document.
|
RealmResultTask<UpdateResult> |
updateMany(Bson filter,
Bson update)
Update all documents in the collection according to the specified arguments.
|
RealmResultTask<UpdateResult> |
updateMany(Bson filter,
Bson update,
UpdateOptions updateOptions)
Update all documents in the collection according to the specified arguments.
|
RealmResultTask<UpdateResult> |
updateOne(Bson filter,
Bson update)
Update a single document in the collection according to the specified arguments.
|
RealmResultTask<UpdateResult> |
updateOne(Bson filter,
Bson update,
UpdateOptions updateOptions)
Update a single document in the collection according to the specified arguments.
|
RealmEventStreamTask<DocumentT> |
watch()
Watches a collection.
|
RealmEventStreamTask<DocumentT> |
watch(BsonValue... ids)
Watches specified IDs in a collection.
|
RealmEventStreamTask<DocumentT> |
watch(ObjectId... ids)
Watches specified IDs in a collection.
|
RealmEventStreamAsyncTask<DocumentT> |
watchAsync()
Watches a collection asynchronously.
|
RealmEventStreamAsyncTask<DocumentT> |
watchAsync(BsonValue... ids)
Watches specified IDs in a collection asynchronously.
|
RealmEventStreamAsyncTask<DocumentT> |
watchAsync(ObjectId... ids)
Watches specified IDs in a collection asynchronously.
|
RealmEventStreamTask<DocumentT> |
watchWithFilter(BsonDocument matchFilter)
Watches a collection.
|
RealmEventStreamTask<DocumentT> |
watchWithFilter(Document matchFilter)
Watches a collection.
|
RealmEventStreamAsyncTask<DocumentT> |
watchWithFilterAsync(BsonDocument matchFilter)
Watches a collection asynchronously.
|
RealmEventStreamAsyncTask<DocumentT> |
watchWithFilterAsync(Document matchFilter)
Watches a collection asynchronously.
|
MongoCollection<DocumentT> |
withCodecRegistry(CodecRegistry codecRegistry)
Creates a new MongoCollection instance with a different codec registry.
|
<NewDocumentT> |
withDocumentClass(Class<NewDocumentT> clazz)
Creates a new MongoCollection instance with a different default class to cast any
documents returned from the database into.
|
public MongoNamespace getNamespace()
public String getName()
public Class<DocumentT> getDocumentClass()
If you used the simple MongoDatabase.getCollection(String) to get this collection,
this is org.bson.Document.
public CodecRegistry getCodecRegistry()
CodecRegistry for this collectionpublic <NewDocumentT> MongoCollection<NewDocumentT> withDocumentClass(Class<NewDocumentT> clazz)
NewDocumentT - The type that the new collection will encode documents from and decode
documents to.clazz - the default class to which any documents returned from the database
will be cast.public MongoCollection<DocumentT> withCodecRegistry(CodecRegistry codecRegistry)
codecRegistry - the new CodecRegistry for the
collection.public RealmResultTask<Long> count()
public RealmResultTask<Long> count(Bson filter)
filter - the query filterpublic RealmResultTask<Long> count(Bson filter, CountOptions options)
filter - the query filteroptions - the options describing the countpublic RealmResultTask<DocumentT> findOne()
public <ResultT> RealmResultTask<ResultT> findOne(Class<ResultT> resultClass)
ResultT - the target document typeresultClass - the class to decode each document intopublic RealmResultTask<DocumentT> findOne(Bson filter)
filter - the query filterpublic <ResultT> RealmResultTask<ResultT> findOne(Bson filter, Class<ResultT> resultClass)
ResultT - the target document type of the iterable.filter - the query filterresultClass - the class to decode each document intopublic RealmResultTask<DocumentT> findOne(Bson filter, FindOptions options)
filter - the query filteroptions - a FindOptions structpublic <ResultT> RealmResultTask<ResultT> findOne(Bson filter, FindOptions options, Class<ResultT> resultClass)
ResultT - the target document type of the iterable.filter - the query filteroptions - a FindOptions structresultClass - the class to decode each document intopublic FindIterable<DocumentT> find()
All documents will be delivered in the form of a FindIterable from which individual
elements can be extracted.
public FindIterable<DocumentT> find(FindOptions options)
FindOptions to build the query.
All documents will be delivered in the form of a FindIterable from which individual
elements can be extracted.
options - a FindOptions struct for building the querypublic <ResultT> FindIterable<ResultT> find(Class<ResultT> resultClass)
All documents will be delivered in the form of a FindIterable from which individual
elements can be extracted.
ResultT - the target document type of the iterable.resultClass - the class to decode each document intopublic <ResultT> FindIterable<ResultT> find(Class<ResultT> resultClass, FindOptions options)
FindOptions to build the query.
All documents will be delivered in the form of a FindIterable from which individual
elements can be extracted.
ResultT - the target document type of the iterable.resultClass - the class to decode each document intooptions - a FindOptions struct for building the querypublic FindIterable<DocumentT> find(Bson filter)
All documents will be delivered in the form of a FindIterable from which individual
elements can be extracted.
filter - the query filterpublic FindIterable<DocumentT> find(Bson filter, FindOptions options)
FindOptions
to build the query.
All documents will be delivered in the form of a FindIterable from which individual
elements can be extracted.
filter - the query filteroptions - a FindOptions structpublic <ResultT> FindIterable<ResultT> find(Bson filter, Class<ResultT> resultClass)
All documents will be delivered in the form of a FindIterable from which individual
elements can be extracted.
ResultT - the target document type of the iterable.filter - the query filterresultClass - the class to decode each document intopublic <ResultT> FindIterable<ResultT> find(Bson filter, Class<ResultT> resultClass, FindOptions options)
FindOptions to build the query.
All documents will be delivered in the form of a FindIterable from which individual
elements can be extracted.
ResultT - the target document type of the iterable.filter - the query filterresultClass - the class to decode each document intooptions - a FindOptions structpublic AggregateIterable<DocumentT> aggregate(List<? extends Bson> pipeline)
All documents will be delivered in the form of an AggregateIterable from which
individual elements can be extracted.
pipeline - the aggregation pipelineAggregateIterable from which the results can be extractedpublic <ResultT> AggregateIterable<ResultT> aggregate(List<? extends Bson> pipeline, Class<ResultT> resultClass)
All documents will be delivered in the form of an AggregateIterable from which
individual elements can be extracted.
ResultT - the target document type of the iterable.pipeline - the aggregation pipelineresultClass - the class to decode each document intoAggregateIterable from which the results can be extractedpublic RealmResultTask<InsertOneResult> insertOne(DocumentT document)
document - the document to insertpublic RealmResultTask<InsertManyResult> insertMany(List<? extends DocumentT> documents)
documents - the documents to insertpublic RealmResultTask<DeleteResult> deleteOne(Bson filter)
filter - the query filter to apply the the delete operationpublic RealmResultTask<DeleteResult> deleteMany(Bson filter)
filter - the query filter to apply the the delete operationpublic RealmResultTask<UpdateResult> updateOne(Bson filter, Bson update)
filter - a document describing the query filter, which may not be null.update - a document describing the update, which may not be null. The update to
apply must include only update operators.public RealmResultTask<UpdateResult> updateOne(Bson filter, Bson update, UpdateOptions updateOptions)
filter - a document describing the query filter, which may not be null.update - a document describing the update, which may not be null. The update to
apply must include only update operators.updateOptions - the options to apply to the update operationpublic RealmResultTask<UpdateResult> updateMany(Bson filter, Bson update)
filter - a document describing the query filter, which may not be null.update - a document describing the update, which may not be null. The update to
apply must include only update operators.public RealmResultTask<UpdateResult> updateMany(Bson filter, Bson update, UpdateOptions updateOptions)
filter - a document describing the query filter, which may not be null.update - a document describing the update, which may not be null. The update to
apply must include only update operators.updateOptions - the options to apply to the update operationpublic RealmResultTask<DocumentT> findOneAndUpdate(Bson filter, Bson update)
filter - the query filterupdate - the update documentpublic <ResultT> RealmResultTask<ResultT> findOneAndUpdate(Bson filter, Bson update, Class<ResultT> resultClass)
ResultT - the target document type of the iterable.filter - the query filterupdate - the update documentresultClass - the class to decode each document intopublic RealmResultTask<DocumentT> findOneAndUpdate(Bson filter, Bson update, FindOneAndModifyOptions options)
filter - the query filterupdate - the update documentoptions - a FindOneAndModifyOptions structpublic <ResultT> RealmResultTask<ResultT> findOneAndUpdate(Bson filter, Bson update, FindOneAndModifyOptions options, Class<ResultT> resultClass)
ResultT - the target document type of the iterable.filter - the query filterupdate - the update documentoptions - a FindOneAndModifyOptions structresultClass - the class to decode each document intopublic RealmResultTask<DocumentT> findOneAndReplace(Bson filter, Bson replacement)
filter - the query filterreplacement - the document to replace the matched document withpublic <ResultT> RealmResultTask<ResultT> findOneAndReplace(Bson filter, Bson replacement, Class<ResultT> resultClass)
ResultT - the target document type of the iterable.filter - the query filterreplacement - the document to replace the matched document withresultClass - the class to decode each document intopublic RealmResultTask<DocumentT> findOneAndReplace(Bson filter, Bson replacement, FindOneAndModifyOptions options)
filter - the query filterreplacement - the document to replace the matched document withoptions - a FindOneAndModifyOptions structpublic <ResultT> RealmResultTask<ResultT> findOneAndReplace(Bson filter, Bson replacement, FindOneAndModifyOptions options, Class<ResultT> resultClass)
ResultT - the target document type of the iterable.filter - the query filterreplacement - the document to replace the matched document withoptions - a FindOneAndModifyOptions structresultClass - the class to decode each document intopublic RealmResultTask<DocumentT> findOneAndDelete(Bson filter)
filter - the query filterpublic <ResultT> RealmResultTask<ResultT> findOneAndDelete(Bson filter, Class<ResultT> resultClass)
ResultT - the target document type of the iterable.filter - the query filterresultClass - the class to decode each document intopublic RealmResultTask<DocumentT> findOneAndDelete(Bson filter, FindOneAndModifyOptions options)
filter - the query filteroptions - a FindOneAndModifyOptions structpublic <ResultT> RealmResultTask<ResultT> findOneAndDelete(Bson filter, FindOneAndModifyOptions options, Class<ResultT> resultClass)
ResultT - the target document type of the iterable.filter - the query filteroptions - a FindOneAndModifyOptions structresultClass - the class to decode each document intopublic RealmEventStreamTask<DocumentT> watch()
public RealmEventStreamTask<DocumentT> watch(BsonValue... ids)
ids - the ids to watch.public RealmEventStreamTask<DocumentT> watch(ObjectId... ids)
BsonValue instances of ObjectId by wrapping them in
BsonObjectId instances for the user.ids - unique object identifiers of the IDs to watch.public RealmEventStreamTask<DocumentT> watchWithFilter(Document matchFilter)
BsonDocument instances for the user.
See how to define a match filter.
Defining the match expression to filter ChangeEvents is similar to how to define the match expression for triggers
matchFilter - the $match filter to apply to incoming change eventspublic RealmEventStreamTask<DocumentT> watchWithFilter(BsonDocument matchFilter)
See how to define a match filter.
Defining the match expression to filter ChangeEvents is similar to how to define the match expression for triggers
matchFilter - the $match filter to apply to incoming change eventspublic RealmEventStreamAsyncTask<DocumentT> watchAsync()
public RealmEventStreamAsyncTask<DocumentT> watchAsync(BsonValue... ids)
ids - the ids to watch.public RealmEventStreamAsyncTask<DocumentT> watchAsync(ObjectId... ids)
BsonValue instances of ObjectId by wrapping them in
BsonObjectId instances for the user.ids - unique object identifiers of the IDs to watch.public RealmEventStreamAsyncTask<DocumentT> watchWithFilterAsync(Document matchFilter)
BsonDocument instances for the user.
See how to define a match filter.
Defining the match expression to filter ChangeEvents is similar to how to define the match expression for triggers
matchFilter - the $match filter to apply to incoming change eventspublic RealmEventStreamAsyncTask<DocumentT> watchWithFilterAsync(BsonDocument matchFilter)
See how to define a match filter.
Defining the match expression to filter ChangeEvents is similar to how to define the match expression for triggers
matchFilter - the $match filter to apply to incoming change events