kmongo / org.litote.kmongo

Package org.litote.kmongo

Types

Id

A unique document identifier.

interface Id<T>

KMongo

Main object used to create a MongoClient instance.

object KMongo

MongoOperator

List all known mongo operators, used in string templates.

enum class MongoOperator

SetTo

A property set to a new value used in update operations.

data class SetTo<out T>

Extensions for External Classes

com.mongodb.client.ChangeStreamIterable

com.mongodb.client.DistinctIterable

com.mongodb.client.FindIterable

com.mongodb.client.MapReduceIterable

com.mongodb.client.model.IndexModel

com.mongodb.client.MongoCollection

com.mongodb.client.MongoDatabase

com.mongodb.client.MongoIterable

kotlin.Any

kotlin.reflect.KProperty

kotlin.reflect.KProperty1

kotlin.String

org.bson.Document

Properties

EMPTY_BSON

An immutable empty Bson.

val EMPTY_BSON: Bson

Functions

addEachToSet

Creates an update that adds each of the given values to the array value of the property, unless the value is already present, in which case it does nothing

fun <T> addEachToSet(property: KProperty<Iterable<T>?>, values: List<T>): Bson

addFields

Creates an $addFields pipeline stage

fun addFields(vararg fields: Field<*>): Bson
fun addFields(fields: List<Field<*>>): Bson

addToSet

Creates an update that adds the given value to the array value of the property, unless the value is already present, in which case it does nothing

fun <T> addToSet(property: KProperty<Iterable<T>?>, value: T): Bson

and

Creates a filter that performs a logical AND of the provided list of filters. Note that this will only generate a "$and" operator if absolutely necessary, as the query language implicity ands together all the keys. In other words, a query expression like:

fun and(filters: Iterable<Bson?>): Bson
fun and(vararg filters: Bson?): Bson

ascending

Create a sort specification for an ascending sort on the given properties.

fun ascending(vararg properties: KProperty<*>): Bson
fun ascending(properties: List<KProperty<*>>): Bson

ascendingIndex

Create an index key for an ascending index on the given fields.

fun ascendingIndex(vararg properties: KProperty<*>): Bson
fun ascendingIndex(properties: Iterable<KProperty<*>>): Bson

bitwiseAnd

Creates an update that performs a bitwise and between the given integer value and the integral value of the property.

fun <T : Number?> bitwiseAnd(property: KProperty<T>, value: Int): Bson

Creates an update that performs a bitwise and between the given long value and the integral value of the property.

fun <T : Number?> bitwiseAnd(property: KProperty<T>, value: Long): Bson

bitwiseOr

Creates an update that performs a bitwise or between the given integer value and the integral value of the property.

fun <T : Number?> bitwiseOr(property: KProperty<T>, value: Int): Bson

Creates an update that performs a bitwise or between the given long value and the integral value of the property.

fun <T : Number?> bitwiseOr(property: KProperty<T>, value: Long): Bson

bitwiseXor

Creates an update that performs a bitwise xor between the given integer value and the integral value of the property.

fun <T : Number?> bitwiseXor(property: KProperty<T>, value: Int): Bson

Creates an update that performs a bitwise xor between the given long value and the integral value of the property.

fun <T : Number?> bitwiseXor(property: KProperty<T>, value: Long): Bson

bucket

Creates a $bucket pipeline stage

fun <TExpression, Boundary> bucket(groupBy: TExpression, boundaries: List<Boundary>, options: BucketOptions = BucketOptions()): Bson

bucketAuto

Creates a $bucketAuto pipeline stage

fun <TExpression> bucketAuto(groupBy: TExpression, buckets: Int, options: BucketAutoOptions = BucketAutoOptions()): Bson

combine

Combine a list of updates into a single update.

fun combine(vararg updates: Bson): Bson
fun combine(updates: List<Bson>): Bson

cond

Returns a $cond expression.

fun <BooleanExpression : Any, ThenExpression : Any, ElseExpression : Any> cond(booleanExpression: BooleanExpression, thenExpression: ThenExpression, elseExpression: ElseExpression): Bson

currentDate

Creates an update that sets the value of the property to the current date as a BSON date.

fun <T> currentDate(property: KProperty<T>): Bson

currentTimestamp

Creates an update that sets the value of the property to the current date as a BSON timestamp.

fun <T> currentTimestamp(property: KProperty<T>): Bson

dayOfMonth

Builds $dayOfMonth expression for this property .

fun dayOfMonth(property: KProperty<TemporalAccessor?>): Bson

dayOfWeek

Builds $dayOfWeek expression for this property .

fun dayOfWeek(property: KProperty<TemporalAccessor?>): Bson

dayOfYear

Builds $dayOfYear expression for this property .

fun dayOfYear(property: KProperty<TemporalAccessor?>): Bson

deleteMany

Creates an DeleteManyModel.

fun <T> deleteMany(filter: Bson, options: DeleteOptions = DeleteOptions()): DeleteManyModel<T>

deleteOne

Creates an DeleteOneModel.

fun <T> deleteOne(filter: Bson, options: DeleteOptions = DeleteOptions()): DeleteOneModel<T>

descending

Create a sort specification for a descending sort on the given properties.

fun descending(vararg properties: KProperty<*>): Bson
fun descending(properties: List<KProperty<*>>): Bson

descendingIndex

Create an index key for a descending index on the given fields.

fun descendingIndex(vararg properties: KProperty<*>): Bson
fun descendingIndex(properties: Iterable<KProperty<*>>): Bson

document

Produce a bson document with the specified elements.

fun document(vararg elements: Bson?): Bson
fun document(elements: Collection<Bson>): Bson

exclude

Creates a projection that excludes all of the given properties.

fun exclude(vararg properties: KProperty<*>): Bson
fun exclude(properties: Iterable<KProperty<*>>): Bson

excludeId

Creates a projection that excludes the _id field. This suppresses the automatic inclusion of _id that is the default, even when other fields are explicitly included.

fun excludeId(): Bson

expr

Creates a filter that matches all documents that validate against the given JSON schema document.

fun <TExpression> expr(expression: TExpression): Bson

facet

Creates a facet pipeline stage

fun facet(facets: List<Facet>): Bson
fun facet(vararg facets: Facet): Bson

fields

Creates a projection that combines the list of projections into a single one. If there are duplicate keys, the last one takes precedence.

fun fields(vararg projections: Bson): Bson
fun fields(projections: List<Bson>): Bson

findOneAndUpdateUpsert

Creates an FindOneAndUpdateOptions and set upsert to true.

fun findOneAndUpdateUpsert(): FindOneAndUpdateOptions

from

Builds Bson for the MongoOperator and the specified expression.

infix fun MongoOperator.from(expression: Any): Bson

geo2dsphere

Create an index key for an 2dsphere index on the given fields.

fun geo2dsphere(vararg properties: KProperty<*>): Bson
fun geo2dsphere(properties: Iterable<KProperty<*>>): Bson

graphLookup

Creates a graphLookup pipeline stage for the specified filter

fun <TExpression> graphLookup(from: String, startWith: TExpression, connectFromField: String, connectToField: String, fieldAs: String, options: GraphLookupOptions = GraphLookupOptions()): Bson

group

Creates a $group pipeline stage for the specified filter

fun <TExpression> group(id: TExpression, vararg fieldAccumulators: BsonField): Bson
fun <TExpression> group(id: TExpression, fieldAccumulators: List<BsonField>): Bson

hour

Builds $hour expression for this property .

fun hour(property: KProperty<TemporalAccessor?>): Bson

inc

Creates an update that increments the value of the property by the given value.

fun <T : Number?> inc(property: KProperty<T>, number: Number): Bson

include

Creates a projection that includes all of the given properties.

fun include(vararg properties: KProperty<*>): Bson
fun include(properties: Iterable<KProperty<*>>): Bson

index

Create a compound index specifications. If any properties are repeated, the last one takes precedence.

fun index(vararg properties: Pair<KProperty<*>, Boolean>): Bson

Create a compound multiple index specifications. If any properties are repeated, the last one takes precedence.

fun index(properties: Map<KProperty<*>, Boolean>): Bson

insertOne

Creates an InsertOneModel.

fun <T> insertOne(document: T): InsertOneModel<T>

jsonSchema

Creates a filter that matches all documents that validate against the given JSON schema document.

fun jsonSchema(schema: Bson): Bson

limit

Creates a $limit pipeline stage for the specified filter

fun limit(limit: Int): Bson

lookup

Creates a $lookup pipeline stage for the specified filter

fun lookup(from: String, localField: String, foreignField: String, newAs: String): Bson

Creates a $lookup pipeline stage, joining the current collection with the one specified in from using the given pipeline

fun lookup(from: String, let: List<Variable<out Any>>? = null, resultProperty: KProperty<Any?>, vararg pipeline: Bson): Bson

match

Creates a $match pipeline stage for the specified filter

fun match(filter: Bson): Bson

Creates a $match pipeline stage with $and on each filter.

fun match(vararg filters: Bson): Bson

millisecond

Builds $millisecond expression for this property .

fun millisecond(property: KProperty<TemporalAccessor?>): Bson

minute

Builds $minute expression for this property .

fun minute(property: KProperty<TemporalAccessor?>): Bson

month

Builds $month expression for this property .

fun month(property: KProperty<TemporalAccessor?>): Bson

mul

Creates an update that multiplies the value of the property by the given number.

fun <T : Number?> mul(property: KProperty<T>, number: Number): Bson

newId

Generate a new Id with the IdGenerator.defaultGenerator.

fun <T> newId(): Id<T>

nor

Creates a filter that performs a logical NOR operation on all the specified filters.

fun nor(vararg filters: Bson): Bson
fun nor(filters: Iterable<Bson>): Bson

not

Creates a filter that matches all documents that do not match the passed in filter. Requires the field name to passed as part of the value passed in and lifts it to create a valid "$not" query:

fun not(filter: Bson): Bson

or

Creates a filter that preforms a logical OR of the provided list of filters.

fun or(filters: Iterable<Bson?>): Bson
fun or(vararg filters: Bson?): Bson

orderBy

Combine multiple sort specifications. If any properties are repeated, the last one takes precedence.

fun orderBy(vararg sorts: KProperty<*>, ascending: Boolean = true): Bson
fun orderBy(sorts: List<KProperty<*>>, ascending: Boolean = true): Bson
fun orderBy(sorts: Map<out KProperty<Any?>, Boolean>): Bson

out

Creates a $out pipeline stage for the specified filter

fun out(collectionName: String): Bson

popFirst

Creates an update that pops the first element of an array that is the value of the property.

fun <T> popFirst(property: KProperty<T>): Bson

popLast

Creates an update that pops the last element of an array that is the value of the property.

fun <T> popLast(property: KProperty<T>): Bson

project

Creates a $project pipeline stage for the specified getProjection

fun project(projection: Bson): Bson

Creates a $project pipeline stage for all specified properties

fun project(vararg properties: KProperty<*>): Bson
fun project(vararg properties: Pair<KProperty<*>, Any?>): Bson
fun project(vararg projections: Bson): Bson
fun project(properties: Map<out KProperty<*>, Any?>): Bson

pull

Creates an update that removes all instances of the given value from the array value of the property.

fun <T> pull(property: KProperty<Iterable<T?>?>, value: T?): Bson

pullAll

Creates an update that removes all instances of the given values from the array value of the property.

fun <T> pullAll(property: KProperty<Iterable<T>?>, values: List<T?>?): Bson

pullByFilter

Creates an update that removes all instances of the given value from the array value of the property.

fun pullByFilter(property: KProperty<*>, filter: Bson): Bson

Creates an update that removes from an array all elements that match the given filter.

fun pullByFilter(filter: Bson): Bson

push

Creates an update that adds the given value to the array value of the property.

fun <T> push(property: KProperty<Iterable<T>?>, value: T): Bson

pushEach

Creates an update that adds each of the given values to the array value of the property, applying the given options for positioning the pushed values, and then slicing and/or sorting the array.

fun <T> pushEach(property: KProperty<Iterable<T>?>, values: List<T?>, options: PushOptions = PushOptions()): Bson

rename

Creates an update that renames a field.

fun <T> rename(property: KProperty<T?>, newProperty: KProperty<T>): Bson

replaceOne

Creates an ReplaceOneModel.

fun <T> replaceOne(filter: Bson, replacement: T, options: ReplaceOptions = ReplaceOptions()): ReplaceOneModel<T>

replaceRoot

Creates a $replaceRoot pipeline stage

fun <TExpression> replaceRoot(value: TExpression): Bson

replaceUpsert

Creates an ReplaceOptions and set upsert to true.

fun replaceUpsert(): ReplaceOptions

sample

Creates a $sample pipeline stage with the specified sample size

fun sample(size: Int): Bson

second

Builds $second expression for this property .

fun second(property: KProperty<TemporalAccessor?>): Bson

set

Creates an update that sets the values of the properties to the specified values.

fun set(vararg properties: SetTo<*>): Bson

setOnInsert

Creates an update that sets the value of the property to the given value, but only if the update is an upsert that results in an insert of a document.

fun <T> setOnInsert(property: KProperty<T?>, value: T): Bson

setValue

Creates an update that sets the value of the property to the given value.

fun <T> setValue(property: KProperty<T?>, value: T?): Bson

skip

Creates a $skip pipeline stage

fun skip(skip: Int): Bson

sort

Creates a $sort pipeline stage for the specified sort specification

fun sort(sort: Bson): Bson

sortByCount

Creates a $sortByCount pipeline stage for the specified filter

fun <TExpression> sortByCount(filter: TExpression): Bson

text

Creates a filter that matches all documents matching the given the search term with the given text search options.

fun text(search: String, textSearchOptions: TextSearchOptions = TextSearchOptions()): Bson

unset

Creates an update that deletes the property with the given name.

fun <T> unset(property: KProperty<T>): Bson

unwind

Creates a $unwind pipeline stage for the specified field name, which must be prefixed by a '$' sign.

fun unwind(fieldName: String, unwindOptions: UnwindOptions = UnwindOptions()): Bson

updateMany

Creates an UpdateManyModel.

fun <T> updateMany(filter: Bson, update: Bson, options: UpdateOptions = UpdateOptions()): UpdateManyModel<T>

updateOne

Creates an UpdateOneModel.

fun <T> updateOne(filter: Bson, update: Bson, options: UpdateOptions = UpdateOptions()): UpdateOneModel<T>

upsert

Creates an UpdateOptions and set upsert to true.

fun upsert(): UpdateOptions

week

Builds $week expression for this property .

fun week(property: KProperty<TemporalAccessor?>): Bson

where

Creates a filter that matches all documents for which the given expression is true.

fun where(javaScriptExpression: String): Bson

year

Builds $year expression for this property .

fun year(property: KProperty<TemporalAccessor?>): Bson