findOne

suspend fun <T : Any> MongoCollection<T>.findOne(filter: String = KMongoUtil.EMPTY_JSON): T?
suspend fun <T : Any> MongoCollection<T>.findOne(filter: Bson): T?

Finds the first document that match the filter in the collection.

Return

the first item returned or null

Parameters

filter

the query filter


suspend fun <T : Any> MongoCollection<T>.findOne(vararg filters: Bson?): T?

Finds the first document that match the filters in the collection.

Return

the first item returned or null

Parameters

filters

the query filters


inline suspend fun <T : Any> MongoCollection<T>.findOne(filters: () -> Bson): T?

Finds the first document that match the filter in the collection.

Return

the first item returned or null

Parameters

filters

the query filters


suspend fun <T : Any> MongoCollection<T>.findOne(clientSession: ClientSession, filter: String = KMongoUtil.EMPTY_JSON): T?
suspend fun <T : Any> MongoCollection<T>.findOne(clientSession: ClientSession, filter: Bson): T?

Finds the first document that match the filter in the collection.

Return

the first item returned or null

Parameters

clientSession

the client session with which to associate this operation

filter

the query filter


suspend fun <T : Any> MongoCollection<T>.findOne(clientSession: ClientSession, vararg filters: Bson?): T?

Finds the first document that match the filters in the collection.

Return

the first item returned or null

Parameters

clientSession

the client session with which to associate this operation

filters

the query filters


inline suspend fun <T : Any> MongoCollection<T>.findOne(clientSession: ClientSession, filters: () -> Bson): T?

Finds the first document that match the filter in the collection.

Return

the first item returned or null

Parameters

clientSession

the client session with which to associate this operation

filters

the query filters