Skip to content

SchemaPropertiesQuery

Types

Property

sealed interface Property<R>

Allows specifying additional configuration on this property.

SchemaPropertyQuery

Operators available within SchemaQuery.SchemaPropertiesQuery.property.

Properties

context

The context used to generate this expression.

field

Converts a Kotlin property into a Field.

Functions

accept

@LowLevelApi
@DangerousMongoApi
abstract override fun accept(node: BsonNode)

Adds a new node as a child of this one.

acceptAll

Adds any number of nodes into this one.

additionalProperties

abstract fun additionalProperties(title: String, schema: SchemaQuery<*>.() -> Unit)

Declares constraints on any property not explicitly declared with property or properties.

By default, any property not declared in the schema is allowed, no matter its type.

Example

users.find {
    schema("User") {
        properties {
            property("name") {
                type(BsonType.String)
            }
            additionalProperties("Extra") {
                type(BsonType.String)
            }
        }
    }
}

External resources

abstract fun additionalProperties(allowed: Boolean)

Explicitly controls whether additional properties beyond those declared with property are allowed.

  • additionalProperties(true): Explicitly allow properties not declared in the schema (default behavior).

  • additionalProperties(false): Explicitly forbid properties not declared in the schema.

Example

users.find {
    schema("User") {
        properties {
            property("name") {
                type(BsonType.String)
            }
            additionalProperties(allowed = false)
        }
    }
}

External resources

div

open operator fun <Root, Parent, Child> KProperty1<Root, Parent>.div(child: KProperty1<Parent & Any, Child>): Field<Root, Child>

Refers to child as a nested field of the current field.

open operator fun <Root, Type, Child> Field<Root, Type>.div(child: KProperty1<in Type & Any, Child>): Field<Root, Child>

Refers to child as a nested field of the current field.

open operator fun <Root, Type, Child> Field<Root, Type>.div(child: Field<Type, Child>): Field<Root, Child>

Refers to child as a nested field of the current field.

freeze

@LowLevelApi
abstract override fun freeze()

Makes this node immutable.

get

open operator fun <Root, Type> KProperty1<Root, Collection<Type>>.get(index: Int): Field<Root, Type>

Refers to a specific item in an array, by its index.

open operator fun <Root, Type> KProperty1<Root, Map<String, Type>>.get(index: String): Field<Root, Type>

Refers to a specific item in a map, by its name.

@JvmName(name = "bsonItem")
operator fun <Root, Child> KProperty1<Root, BsonArray>.get(index: Int): Field<Root, Child>

Refers to a child item of a field of type BsonArray.

@JvmName(name = "bsonField")
operator fun <Root, Child> KProperty1<Root, BsonDocument>.get(field: String): Field<Root, Child>

Refers to a child field of a field of type BsonDocument.

@JvmName(name = "bsonField")
operator fun <Child> BsonDocument.Companion.get(field: String): Field<BsonDocument, Child>

Refers to a root field of the document being analyzed.

open operator fun <Root, Type> Field<Root, Collection<Type>>.get(index: Int): Field<Root, Type>

Refers to a specific item in an array, by its index.

open operator fun <Root, Type> Field<Root, Map<String, Type>>.get(key: String): Field<Root, Type>

Refers to a specific item in a map, by its name.

@JvmName(name = "bsonItem")
operator fun <Root, Child> Field<Root, BsonArray>.get(index: Int): Field<Root, Child>

Refers to a child item of a field of type BsonArray.

@JvmName(name = "bsonField")
operator fun <Root, Child> Field<Root, BsonDocument>.get(field: String): Field<Root, Child>

Refers to a child field of a field of type BsonDocument.

properties

abstract fun <E> properties(@Language(value = "JSRegexp") pattern: String, schema: SchemaQuery<E>.() -> Unit)

Declares constraints on any property whose name matches the regular expression pattern.

pattern must follow the ECMA 262 regular expression dialect.

Example

users.find {
    schema("User") {
        properties {
            properties("^str_.*$") {
                type(BsonType.String)
            }
        }
    }
}

External resources

property

Declares constraints on a property named name.

If required is true, the property must be present in the document.

Example

class User(
    val _id: ObjectId,
    val name: String,
)

users.find {
    schema("User") {
        properties {
            property("name") {
                type(BsonType.String)
            }
        }
    }
}

External resources

Declares constraints on a property represented by field.

If required is true, the property must be present in the document.

Example

class User(
    val _id: ObjectId,
    val name: String,
)

users.find {
    schema("User") {
        properties {
            property(User::name) {
                type(BsonType.String)
            }
        }
    }
}

External resources

simplify

@LowLevelApi
abstract fun simplify(): BsonNode?

Returns a simplified (but equivalent) expression to the current expression.

toBson

Writes the result of simplifying to a new BsonDocument.

toString

abstract override fun toString(): String

JSON representation of this expression.

unsafe

open infix fun <Root, Child> KProperty1<Root, *>.unsafe(child: String): Field<Root, Child>

Refers to a field child of the current field, with no compile-time safety.

open infix fun <Root, Child> KProperty1<Root, *>.unsafe(child: KProperty1<*, Child>): Field<Root, Child>

Refers to a field child of the current field, without checking that it is a field available on the current object.

open infix fun <Root, Child> KProperty1<Root, *>.unsafe(child: Field<*, Child>): Field<Root, Child>

Refers to a field child of the current field, without checking that it is a field available on the current object.

open infix fun <Root, Child> Field<Root, *>.unsafe(child: KProperty1<*, Child>): Field<Root, Child>

Refers to a field child of the current field, without checking that it is a field available on the current object.

open infix fun <Root, Child> Field<Root, *>.unsafe(child: Field<*, Child>): Field<Root, Child>

Refers to a field child of the current field, without checking that it is a field available on the current object.

open infix fun <Root, Type, Child> Field<Root, Type>.unsafe(child: String): Field<Root, Child>

Refers to a field child of the current field, with no compile-time safety.

unsafeCast

Overwrites the represented type of this field.

writeTo

@LowLevelApi
abstract override fun writeTo(writer: BsonFieldWriter)

Writes the result of simplifying this expression into writer.