MongoCollection

interface MongoCollection<T>

A mongo collection provides access to retrieve and update data from the database's collection with specific typed serialization.

This API corresponds to the Atlas App Service "MongoDB API". Please consult the MongoDB API Reference for a detailed description of methods and arguments.

Input arguments and responses to the App Service HTTP requests will be serialized from and to the type T using Kotlin's Serialization framework and can be customized by Serializable-annotations or customizing the EJson-serializer passed to the various MongoClient, MongoDatabase and MongoCollection-factory methods. For details on configuring the serialization see MongoClient.

All operations on a MongoCollection will throw an:

  • ServiceException if the underlying App Service HTTP requests fails

  • SerializationException if input arguments cannot be serialized to a valid EJson document or if the App Service response could not be deserialized to the return types.

Parameters

T

the default type that remote entities of the collection will be serialized from and to.

Properties

Link copied to clipboard
abstract val name: String

Name of the remote collection.

Functions

Link copied to clipboard
inline suspend fun <T> MongoCollection<*>.aggregate(pipeline: List<BsonDocument>): List<T>

Execute an aggregate pipeline on the remote collection.

Link copied to clipboard
suspend fun MongoCollection<*>.count(filter: BsonDocument? = null, limit: Long? = null): Long

Returns the number of documents in the collection.

Link copied to clipboard
suspend fun MongoCollection<*>.deleteMany(filter: BsonDocument): Long

Delete multiple objects from the remote collection.

Link copied to clipboard
suspend fun MongoCollection<*>.deleteOne(filter: BsonDocument): Boolean

Delete a single object from the remote collection.

Link copied to clipboard
inline suspend fun <T> MongoCollection<T>.find(filter: BsonDocument? = null, projection: BsonDocument? = null, sort: BsonDocument? = null, limit: Long? = null): List<T>

Retrieve multiple object from the remote collection.

Link copied to clipboard
inline suspend fun <T> MongoCollection<T>.findOne(filter: BsonDocument? = null, projection: BsonDocument? = null, sort: BsonDocument? = null): T?

Retrieve a single object from the remote collection.

Link copied to clipboard
inline suspend fun <T> MongoCollection<T>.findOneAndDelete(filter: BsonDocument, projection: BsonDocument? = null, sort: BsonDocument? = null): T?

Find and delete a single object in the remote collection.

Link copied to clipboard
inline suspend fun <T> MongoCollection<T>.findOneAndReplace(filter: BsonDocument, document: BsonDocument, projection: BsonDocument? = null, sort: BsonDocument? = null, upsert: Boolean = false, returnNewDoc: Boolean = false): T?

Find and replace or insert a single new object in the remote collection.

Link copied to clipboard
inline suspend fun <T> MongoCollection<T>.findOneAndUpdate(filter: BsonDocument, update: BsonDocument, projection: BsonDocument? = null, sort: BsonDocument? = null, upsert: Boolean = false, returnNewDoc: Boolean = false): T?

Find and update or insert a single new object in the remote collection.

Link copied to clipboard
@JvmName(name = "insertManyTyped")
inline suspend fun <T : Any> MongoCollection<*>.insertMany(documents: Collection<T>): List<Any>

Insert a list of object into the remote collection.

Link copied to clipboard
inline suspend fun <T : Any> MongoCollection<T>.insertOne(document: T): Any

Insert a single object into the remote collection.

Link copied to clipboard
inline suspend fun MongoCollection<*>.updateMany(filter: BsonDocument, update: BsonDocument, upsert: Boolean = false): UpdateManyResult

Update multiple objects or insert a single new object in the remote collection.

Link copied to clipboard
inline suspend fun MongoCollection<*>.updateOne(filter: BsonDocument, update: BsonDocument, upsert: Boolean = false): UpdateOneResult

Update or insert a single object in the remote collection.

Link copied to clipboard
@ExperimentalKBsonSerializerApi
abstract fun <T> withDocumentClass(eJson: EJson? = null): MongoCollection<T>

Get an instance of the same collection with a different set of default types serialization.