findOne

fun <T : Any> MongoCollection<T>.findOne(filter: String = KMongoUtil.EMPTY_JSON): T?
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


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 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


fun <T : Any> MongoCollection<T>.findOne(clientSession: ClientSession, filter: String = KMongoUtil.EMPTY_JSON): T?
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


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 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