BsonFactory
Entrypoint for creating BsonDocument and BsonArray instances.
Navigating BSON types
This interface is part of the BSON trinity:
BsonDocument represents an entire BSON document.
BsonArray represents an array of BSON values.
BsonValue represents a single value in isolation.
Serialization
This interface encapsulates the configuration of the serialization library in use.
For example, if you use the official java or Kotlin MongoDB drivers, all BSON values built by this factory will respect the configured CodecRegistry.
Usage
To create the following BSON document:
{
"name": "Bob",
"isAlive": true,
"children": [
{
"name": "Alice"
},
{
"name": "Charles"
}
]
}use the code:
val document = factory.buildDocument {
writeString("name", "Alice")
writeBoolean("isAlive", true)
writeArray("children") {
writeDocument {
writeString("name", "Alice")
}
writeDocument {
writeString("name", "Charles")
}
}
}The value can then be read into Kotlin types:
data class User(
val name: String,
val isAlive: Boolean,
val children: List<Child>,
)
data class Child(
val name: String,
)
val user = document.decode<User>()
println(user.children[0].name) // AliceFunctions
Instantiates a new BSON array.
Instantiates a new BSON array representing the provided instance.
Instantiates a new BSON document.
Instantiates a new BSON document representing the provided instance.
Writes an arbitrary Kotlin obj into a top-level BSON document.
Writes an arbitrary Kotlin obj into a top-level BSON document.
Instantiates a new BSON document by reading its bytes representation.
Returns a BsonDocument that is tied to this factory, that represents the same data as document.