Join us at MongoDB.local London on 7 May to unlock new possibilities for your data. Use WEB50 to save 50%.
Register now >
Docs Menu
Docs Home
/ /
io.realm.mongodb.mongo

Class MongoCollection

java.lang.Object
io.realm.mongodb.mongo.MongoCollection

La interfaz MongoCollection proporciona acceso de lectura y escritura a documentos. Utiliza MongoDatabase.getCollection para obtener una instancia de colección.

Antes de permitir cualquier acceso, debe haber un usuario activo con la sesión iniciada.

Tip

  • MongoDatabase

Modificador y Tipo
Método y descripción

Agrega documentos según el pipeline de agregación especificado, definiendo una clase de salida.

Agrega documentos según el proceso de agregación especificado.

Bson filter,
CountOptions options
)

Counts the number of documents in the collection according to the given options.

Bson filter
)

Counts the number of documents in the collection according to the given options.

Cuenta el número de documentos en la colección.

Bson filter
)

Removes all documents from the collection that match the given query filter.

Bson filter
)

Remueve como máximo un documento de la colección que coincide con el filtro dado.

find <ResultT >(
Bson filter,
FindOptions options
)

Busca todos los documentos en la colección que coinciden con el filtro dado, especificando una clase de salida y utilizando también FindOptions para construir la query.

find <ResultT >(
Bson filter,
)

Finds all documents in the collection that match the given filter specifying an output class.

Bson filter,
FindOptions options
)

Finds all documents in the collection that match the given filter using FindOptions to build the query.

Bson filter
)

Finds all documents in the collection that match the given filter.

find <ResultT >(
)

Finds all documents in the collection specifying an output class and also using FindOptions to build the query.

find <ResultT >(
)

Finds all documents in the collection specifying an output class.

FindOptions options
)

Finds all documents in the collection using FindOptions to build the query.

find ()

Encuentra todos los documentos en la colección.

findOne <ResultT >(
Bson filter,
FindOptions options,
)

Finds a document in the collection.

Bson filter,
FindOptions options
)

Finds a document in the collection.

findOne <ResultT >(
Bson filter,
)

Finds a document in the collection.

Bson filter
)

Finds a document in the collection.

findOne <ResultT >(
)

Finds a document in the collection.

Finds a document in the collection.

findOneAndDelete <ResultT >(
Bson filter,
)

Finds a document in the collection and delete it.

Finds a document in the collection and delete it.

findOneAndDelete <ResultT >(
Bson filter,
)

Finds a document in the collection and delete it.

Bson filter
)

Finds a document in the collection and delete it.

findOneAndReplace <ResultT >(
Bson filter,
Bson replacement,
)

Finds a document in the collection and replaces it with the given document.

Bson filter,
Bson replacement,
)

Finds a document in the collection and replaces it with the given document.

findOneAndReplace <ResultT >(
Bson filter,
Bson replacement,
)

Finds a document in the collection and replaces it with the given document.

Bson filter,
Bson replacement
)

Finds a document in the collection and replaces it with the given document.

findOneAndUpdate <ResultT >(
Bson filter,
Bson update,
)

Finds a document in the collection and performs the given update.

Bson filter,
Bson update,
)

Finds a document in the collection and performs the given update.

findOneAndUpdate <ResultT >(
Bson filter,
Bson update,
)

Finds a document in the collection and performs the given update.

Bson filter,
Bson update
)

Finds a document in the collection and performs the given update.

Registro de códecspúblico

Obtiene el registro de códecs para MongoCollection.

public Class

Gets the class of documents stored in this collection.

public String

Obtiene el nombre de esta colección

Obtiene el espacio de nombres de esta colección, es decir

Inserta uno o más documentos.

DocumentT document
)

Inserts the provided document.

Bson filter,
Bson update,
UpdateOptions updateOptions
)

Update all documents in the collection according to the specified arguments.

Bson filter,
Bson update
)

Update all documents in the collection according to the specified arguments.

Bson filter,
Bson update,
UpdateOptions updateOptions
)

Update a single document in the collection according to the specified arguments.

Bson filter,
Bson update
)

Update a single document in the collection according to the specified arguments.

ObjectId[] ids
)

Watches specified IDs in a collection.

BsonValue[] ids
)

Watches specified IDs in a collection.

Observa una colección.

ObjectId[] ids
)

Observa identificaciones específicas en una colección de forma asincrónica.

BsonValue[] ids
)

Observa identificaciones específicas en una colección de forma asincrónica.

Watches a collection asynchronously.

BsonDocument matchFilter
)

Observa una colección.

Document matchFilter
)

Observa una colección.

BsonDocument matchFilter
)

Watches a collection asynchronously.

Document matchFilter
)

Watches a collection asynchronously.

CodecRegistry codecRegistry
)

Crea una nueva instancia de MongoCollection con un registro de códecs diferente.

Creates a new MongoCollection instance with a different default class to cast any documents returned from the database into.

  • Métodos heredados de la clase java.lang.Object: getClass , hashCode , equals , clone , toString , notify , notifyAll , wait , wait , wait , finalize

Agrupa documentos según la pipeline de agregación especificada, especificando una clase de salida. Todos los documentos se entregarán en forma de un AggregateIterable del que se pueden extraer elementos individuales.

Type Parameters

  • ResultT - el tipo de documento objetivo del iterable.

Parámetros

  • pipeline - la canalización de agregación

  • resultClass - la clase en la que decodificar cada documento

Devuelve

an AggregateIterable from which the results can be extracted

Aggregates documents according to the specified aggregation pipeline.All documents will be delivered in the form of an AggregateIterable from which individual elements can be extracted.

Parámetros

  • pipeline - la canalización de agregación

Devuelve

an AggregateIterable from which the results can be extracted

Bson filter,
CountOptions options
)

Counts the number of documents in the collection according to the given options.

Parámetros

  • filter - the query filter

  • options - the options describing the count

Devuelve

una tarea que contiene el número de documentos en la colección

Bson filter
)

Counts the number of documents in the collection according to the given options.

Parámetros

  • filter - the query filter

Devuelve

una tarea que contiene el número de documentos en la colección

Cuenta el número de documentos en la colección.

Devuelve

una tarea que contiene el número de documentos en la colección

Bson filter
)

Elimina todos los documentos de la colección que coincidan con el filtro de query proporcionado. Si no hay documentos que coincidan, la colección no se modifica.

Parámetros

  • filter - el filtro de consulta para aplicar la operación de eliminación

Devuelve

a task containing the result of the remove many operation

Bson filter
)

Removes at most one document from the collection that matches the given filter. If no documents match, the collection is not modified.

Parámetros

  • filter - el filtro de consulta para aplicar la operación de eliminación

Devuelve

una tarea que contiene el resultado de la operación de eliminar uno

public FindIterable find <ResultT >(
Bson filter,
FindOptions options
)

Busca todos los documentos en la colección que coinciden con el filtro dado, especificando una clase de salida y utilizando también FindOptions para construir la query.

Todos los documentos se entregarán en forma de FindIterable del que se podrán extraer elementos individuales.

Type Parameters

  • ResultT - el tipo de documento objetivo del iterable.

Parámetros

  • filter - the query filter

  • resultClass - la clase en la que decodificar cada documento

  • options - a FindOptions struct

Devuelve

an iterable containing the result of the find operation

public FindIterable find <ResultT >(
Bson filter,
)

Finds all documents in the collection that match the given filter specifying an output class.All documents will be delivered in the form of a FindIterable from which individual elements can be extracted.

Type Parameters

  • ResultT - el tipo de documento objetivo del iterable.

Parámetros

  • filter - the query filter

  • resultClass - la clase en la que decodificar cada documento

Devuelve

an iterable containing the result of the find operation

Bson filter,
FindOptions options
)

Finds all documents in the collection that match the given filter using FindOptions to build the query.

Todos los documentos se entregarán en forma de FindIterable del que se podrán extraer elementos individuales.

Parámetros

  • filter - the query filter

  • options - a FindOptions struct

Devuelve

an iterable containing the result of the find operation

Bson filter
)

Finds all documents in the collection that match the given filter.All documents will be delivered in the form of a FindIterable from which individual elements can be extracted.

Parámetros

  • filter - the query filter

Devuelve

an iterable containing the result of the find operation

public FindIterable find <ResultT >(
)

Finds all documents in the collection specifying an output class and also using FindOptions to build the query.

Todos los documentos se entregarán en forma de FindIterable del que se podrán extraer elementos individuales.

Type Parameters

  • ResultT - el tipo de documento objetivo del iterable.

Parámetros

  • resultClass - la clase en la que decodificar cada documento

  • options - a FindOptions struct for building the query

Devuelve

an iterable containing the result of the find operation

public FindIterable find <ResultT >(
)

Encuentra todos los documentos en la colección especificando una clase de salida. Todos los documentos se entregarán en forma de FindIterable del cual se pueden extraer elementos individuales.

Type Parameters

  • ResultT - el tipo de documento objetivo del iterable.

Parámetros

  • resultClass - la clase en la que decodificar cada documento

Devuelve

an iterable containing the result of the find operation

FindOptions options
)

Finds all documents in the collection using FindOptions to build the query.

Todos los documentos se entregarán en forma de FindIterable del que se podrán extraer elementos individuales.

Parámetros

Devuelve

an iterable containing the result of the find operation

public FindIterable find ()

Finds all documents in the collection.All documents will be delivered in the form of a FindIterable from which individual elements can be extracted.

Devuelve

an iterable containing the result of the find operation

public RealmResultTask findOne <ResultT >(
Bson filter,
FindOptions options,
)

Finds a document in the collection.

Type Parameters

  • ResultT - el tipo de documento objetivo del iterable.

Parámetros

  • filter - the query filter

  • options - a FindOptions struct

  • resultClass - la clase en la que decodificar cada documento

Devuelve

una tarea que contiene el resultado de la operación encontrar uno

Bson filter,
FindOptions options
)

Finds a document in the collection.

Parámetros

  • filter - the query filter

  • options - a FindOptions struct

Devuelve

una tarea que contiene el resultado de la operación encontrar uno

public RealmResultTask findOne <ResultT >(
Bson filter,
)

Finds a document in the collection.

Type Parameters

  • ResultT - el tipo de documento objetivo del iterable.

Parámetros

  • filter - the query filter

  • resultClass - la clase en la que decodificar cada documento

Devuelve

una tarea que contiene el resultado de la operación encontrar uno

Bson filter
)

Finds a document in the collection.

Parámetros

  • filter - the query filter

Devuelve

una tarea que contiene el resultado de la operación encontrar uno

public RealmResultTask findOne <ResultT >(
)

Finds a document in the collection.

Type Parameters

  • ResultT - the target document type

Parámetros

  • resultClass - la clase en la que decodificar cada documento

Devuelve

una tarea que contiene el resultado de la operación encontrar uno

Finds a document in the collection.

Devuelve

una tarea que contiene el resultado de la operación encontrar uno

Bson filter,
)

Finds a document in the collection and delete it.

Type Parameters

  • ResultT - el tipo de documento objetivo del iterable.

Parámetros

  • filter - the query filter

  • options - una estructura FindOneAndModifyOptions

  • resultClass - la clase en la que decodificar cada documento

Devuelve

a task containing the resulting document

Finds a document in the collection and delete it.

Parámetros

Devuelve

a task containing the resulting document

Bson filter,
)

Finds a document in the collection and delete it.

Type Parameters

  • ResultT - el tipo de documento objetivo del iterable.

Parámetros

  • filter - the query filter

  • resultClass - la clase en la que decodificar cada documento

Devuelve

a task containing the resulting document

Bson filter
)

Finds a document in the collection and delete it.

Parámetros

  • filter - the query filter

Devuelve

a task containing the resulting document

Bson filter,
Bson replacement,
)

Finds a document in the collection and replaces it with the given document.

Type Parameters

  • ResultT - el tipo de documento objetivo del iterable.

Parámetros

  • filter - the query filter

  • replacement - el documento con el que reemplazar el documento emparejado

  • options - una estructura FindOneAndModifyOptions

  • resultClass - la clase en la que decodificar cada documento

Devuelve

a task containing the resulting document

Bson filter,
Bson replacement,
)

Finds a document in the collection and replaces it with the given document.

Parámetros

  • filter - the query filter

  • replacement - el documento con el que reemplazar el documento emparejado

  • options - una estructura FindOneAndModifyOptions

Devuelve

a task containing the resulting document

Bson filter,
Bson replacement,
)

Finds a document in the collection and replaces it with the given document.

Type Parameters

  • ResultT - el tipo de documento objetivo del iterable.

Parámetros

  • filter - the query filter

  • replacement - el documento con el que reemplazar el documento emparejado

  • resultClass - la clase en la que decodificar cada documento

Devuelve

a task containing the resulting document

Bson filter,
Bson replacement
)

Finds a document in the collection and replaces it with the given document.

Parámetros

  • filter - the query filter

  • replacement - el documento con el que reemplazar el documento emparejado

Devuelve

a task containing the resulting document

Bson filter,
Bson update,
)

Finds a document in the collection and performs the given update.

Type Parameters

  • ResultT - el tipo de documento objetivo del iterable.

Parámetros

  • filter - the query filter

  • update - the update document

  • options - una estructura FindOneAndModifyOptions

  • resultClass - la clase en la que decodificar cada documento

Devuelve

a task containing the resulting document

Bson filter,
Bson update,
)

Finds a document in the collection and performs the given update.

Parámetros

Devuelve

a task containing the resulting document

Bson filter,
Bson update,
)

Finds a document in the collection and performs the given update.

Type Parameters

  • ResultT - el tipo de documento objetivo del iterable.

Parámetros

  • filter - the query filter

  • update - the update document

  • resultClass - la clase en la que decodificar cada documento

Devuelve

a task containing the resulting document

Bson filter,
Bson update
)

Finds a document in the collection and performs the given update.

Parámetros

  • filter - the query filter

  • update - the update document

Devuelve

a task containing the resulting document

public CodecRegistry getCodecRegistry ()

Obtiene el registro de códecs para MongoCollection.

Devuelve

El registro de códecs para esta colección

Obtiene la clase de documentos almacenados en esta colección. Si usaste el método simple MongoDatabase.getCollection(String) para obtener esta colección, esto es org.bson.documento .

Devuelve

the class of documents in this collection

public String getName ()

Obtiene el nombre de esta colección

Devuelve

el nombre

Gets the namespace of this collection, i.e. the database and collection names together.

Devuelve

the namespace

Inserta uno o más documentos.

Parámetros

  • documents - the documents to insert

Devuelve

una tarea que contiene el resultado de la operación de inserción múltiple

DocumentT document
)

Inserta el documento proporcionado. Si al documento le falta un identificador, el cliente debe generar uno.

Parámetros

  • document - the document to insert

Devuelve

a task containing the result of the insert one operation

Bson filter,
Bson update,
UpdateOptions updateOptions
)

Update all documents in the collection according to the specified arguments.

Parámetros

  • filter - a document describing the query filter, which may not be null.

  • update - un documento que describe la actualización, la cual podría no ser nula. La actualización que se va a aplicar debe incluir únicamente operadores de actualización.

  • updateOptions - the options to apply to the update operation

Devuelve

a task containing the result of the update many operation

Bson filter,
Bson update
)

Update all documents in the collection according to the specified arguments.

Parámetros

  • filter - a document describing the query filter, which may not be null.

  • update - un documento que describe la actualización, la cual podría no ser nula. La actualización que se va a aplicar debe incluir únicamente operadores de actualización.

Devuelve

a task containing the result of the update many operation

Bson filter,
Bson update,
UpdateOptions updateOptions
)

Update a single document in the collection according to the specified arguments.

Parámetros

  • filter - a document describing the query filter, which may not be null.

  • update - un documento que describe la actualización, la cual podría no ser nula. La actualización que se va a aplicar debe incluir únicamente operadores de actualización.

  • updateOptions - the options to apply to the update operation

Devuelve

a task containing the result of the update one operation

Bson filter,
Bson update
)

Update a single document in the collection according to the specified arguments.

Parámetros

  • filter - a document describing the query filter, which may not be null.

  • update - un documento que describe la actualización, la cual podría no ser nula. La actualización que se va a aplicar debe incluir únicamente operadores de actualización.

Devuelve

a task containing the result of the update one operation

ObjectId[] ids
)

Observa los IDs especificados en una colección. Esta sobrecarga práctica admite el caso de uso deObjectId que no sea BsonValue al envolverlo para el usuario en instancias de BsonObjectId.

Parámetros

  • ids - identificadores únicos de objetos de los ID a observar.

Devuelve

a task that provides access to the stream of change events.

BsonValue[] ids
)

Watches specified IDs in a collection.

Parámetros

  • ids - los IDs a vigilar.

Devuelve

a task that provides access to the stream of change events.

Watches a collection. The resulting stream will be notified of all events on this collection that the active user is authorized to see based on the configured MongoDB Realm rules.

Devuelve

a task that provides access to the stream of change events.

ObjectId[] ids
)

Watches specified IDs in a collection asynchronously. This convenience overload supports the use case of non-BsonValue instances of ObjectId by wrapping them in BsonObjectId instances for the user.

Parámetros

  • ids - identificadores únicos de objetos de los ID a observar.

Devuelve

a task that provides access to the stream of change events.

BsonValue[] ids
)

Observa identificaciones específicas en una colección de forma asincrónica.

Parámetros

  • ids - los IDs a vigilar.

Devuelve

a task that provides access to the stream of change events.

Observa una colección de forma asíncrona. El flujo resultante recibirá notificaciones de todos los eventos de esta colección que el usuario activo esté autorizado a ver, según las reglas de MongoDB Realm configuradas.

Devuelve

a task that provides access to the stream of change events.

BsonDocument matchFilter
)

Watches a collection. The provided BSON document will be used as a match expression filter on the change events coming from the stream.See how to define a match filter .

Definir la expresión de coincidencia para filtrar ChangeEvents es similar a cómo definir la expresión de coincidencia para activadores

Parámetros

  • matchFilter - the $match filter to apply to incoming change events

Devuelve

a task that provides access to the stream of change events.

Document matchFilter
)

Watches a collection. The provided document will be used as a match expression filter on the change events coming from the stream. This convenience overload supports the use of non-BsonDocument instances for the user.

Vea cómo definir un filtro de coincidencia.

Definir la expresión de coincidencia para filtrar ChangeEvents es similar a cómo definir la expresión de coincidencia para activadores

Parámetros

  • matchFilter - the $match filter to apply to incoming change events

Devuelve

a task that provides access to the stream of change events.

BsonDocument matchFilter
)

Supervisa una colección de forma asincrónica. El documento BSON proporcionado se utilizará como un filtro de expresión de coincidencia en los eventos de cambio provenientes del flujo. Consulta cómo definir un filtro de coincidencia .

Definir la expresión de coincidencia para filtrar ChangeEvents es similar a cómo definir la expresión de coincidencia para activadores

Parámetros

  • matchFilter - the $match filter to apply to incoming change events

Devuelve

a task that provides access to the stream of change events.

Document matchFilter
)

Watches a collection asynchronously. The provided document will be used as a match expression filter on the change events coming from the stream. This convenience overload supports the use of non-BsonDocument instances for the user.

Vea cómo definir un filtro de coincidencia.

Definir la expresión de coincidencia para filtrar ChangeEvents es similar a cómo definir la expresión de coincidencia para activadores

Parámetros

  • matchFilter - the $match filter to apply to incoming change events

Devuelve

a task that provides access to the stream of change events.

CodecRegistry codecRegistry
)

Crea una nueva instancia de MongoCollection con un registro de códecs diferente.

Parámetros

  • codecRegistry - the new CodecRegistry for the collection.

Devuelve

a new MongoCollection instance with the different codec registry

Creates a new MongoCollection instance with a different default class to cast any documents returned from the database into.

Type Parameters

  • NewDocumentT - El tipo del que la nueva colección codificará documentos y decodificará documentos a.

Parámetros

  • clazz - la clase por defecto en la que se lanzarán todos los documentos devueltos desde la base de datos.

Devuelve

a new MongoCollection instance with the different default class

Volver

MongoClient

En esta página