Skip to content

BsonValueWriter

@LowLevelApi



interface BsonValueWriter : AnyBsonWriter

Generator of BSON values.

This interface is used to write a generic BSON value. For example, the root BSON value, or a specific value of a field.

To write fields in a BSON document, see BsonFieldWriter.

Instances of this interface are commonly obtained by calling the BsonContext.buildArray function.

Functions

pipe

@LowLevelApi



@DangerousMongoApi



open fun pipe(obj: BsonValueReader)

Writes the arbitrary obj into this writer.

Note that the object will be written as-is, with no safety checks whatsoever. Only use this method if you are absolutely sure attackers cannot control the contents of obj.

If in doubt, prefer using writeObjectSafe.

writeArray

@LowLevelApi



abstract fun writeArray(block: BsonValueWriter.() -> Unit)

writeBinaryData

@LowLevelApi



abstract fun writeBinaryData(type: UByte, data: ByteArray)

writeBoolean

@LowLevelApi



abstract fun writeBoolean(value: Boolean)

writeDateTime

@LowLevelApi



abstract fun writeDateTime(value: Long)

writeDBPointer

@LowLevelApi



abstract fun writeDBPointer(namespace: String, id: ByteArray)
Deprecated

This functionality is deprecated in the BSON specification. See https://bsonspec.org/spec.html

writeDecimal128

@LowLevelApi



abstract fun writeDecimal128(low: Long, high: Long)

writeDocument

@LowLevelApi



abstract fun writeDocument(block: BsonFieldWriter.() -> Unit)

writeDouble

@LowLevelApi



abstract fun writeDouble(value: Double)

writeInstant

@LowLevelApi



open fun writeInstant(value: Instant)

Writes an Instant. Conversion function on top of writeDateTime.

writeInt32

@LowLevelApi



abstract fun writeInt32(value: Int)
@LowLevelApi



open fun writeInt32(value: Short)
@LowLevelApi



open fun writeInt32(value: Byte)

writeInt64

@LowLevelApi



abstract fun writeInt64(value: Long)

writeJavaScript

@LowLevelApi



abstract fun writeJavaScript(code: String)

writeJavaScriptWithScope

@LowLevelApi



abstract fun writeJavaScriptWithScope(code: String)
Deprecated

This functionality is deprecated in the BSON specification. See https://bsonspec.org/spec.html

writeMaxKey

@LowLevelApi



abstract fun writeMaxKey()

writeMinKey

@LowLevelApi



abstract fun writeMinKey()

writeNull

@LowLevelApi



abstract fun writeNull()

writeObjectId

@LowLevelApi



abstract fun writeObjectId(id: ByteArray)
@LowLevelApi



open fun writeObjectId(id: ObjectId)

writeObjectSafe

@LowLevelApi



abstract fun <T> writeObjectSafe(obj: T)

Writes an arbitrary obj into a BSON document.

All nested values are escaped as necessary such that the result is a completely inert BSON document.

writeRegularExpression

@LowLevelApi



abstract fun writeRegularExpression(pattern: String, options: String)

writeString

@LowLevelApi



abstract fun writeString(value: String)

writeSymbol

@LowLevelApi



abstract fun writeSymbol(value: String)
Deprecated

This functionality is deprecated in the BSON specification. See https://bsonspec.org/spec.html

writeTimestamp

@LowLevelApi



abstract fun writeTimestamp(value: Timestamp)

writeUndefined

@LowLevelApi



abstract fun writeUndefined()
Deprecated

This functionality is deprecated in the BSON specification. See https://bsonspec.org/spec.html

writeVector

@LowLevelApi



open fun writeVector(vector: Vector)