Overview
在本指南中,您可以了解 BSON 数据格式、MongoDB 如何使用该格式,以及如何独立于 Kotlin 驱动程序安装 BSON 库。
BSON 数据格式
BSON, or Binary JSON, is the data format that MongoDB uses to organize and store data. This data format includes all JSON data structure types and also supports other types, including dates, different size integers, ObjectId values, and binary data. For a complete list of supported types, see the BSON Types page in the MongoDB server manual.
The binary format is not human-readable, but you can use the Java BSON library to convert it to a JSON representation. To learn more about the relationship between these formats, see the JSON and BSON article.
MongoDB 和 BSON
The Kotlin driver, which uses the BSON library, allows you to work with BSON data by using one of the object types that implements the BSON interface. The following types implement the BSON interface:
文档(BSON 库包)
BsonDocument(BSON 库包)
RawbsonDocument(BSON 库包)
jsonObject (BSON 库包)
BasicDBObject (JVM package)
安装 BSON 库
本节介绍如何将 BSON 库作为依赖项添加到项目中。如果您已将 Kotlin 驱动程序作为依赖项添加到项目中,则可以跳过此步骤,因为 BSON 库已作为驱动程序的必需依赖项包含在内。有关如何将 Kotlin 驱动程序作为依赖项添加到项目中,请参阅 Kotlin 驱动程序入门指南。
提示
物料清单
我们建议将 Java虚拟机(JVM) 驱动程序物料清单 (BOM) 添加到应用程序中,以管理驱动程序文件的版本。这样就无需为 BOM 所涵盖的任何单个包指定版本,从而简化了依赖管理。要学习更多信息,请参阅 Kotlin 驱动程序入门指南。
建议您使用 Maven 或 Gradle 来构建自动化工具,从而管理项目的依赖项。从以下标签页进行选择,从而查看该工具的依赖项声明:
以下代码片段显示 pom.xml 文件的 dependencies 部分中的依赖声明。
<dependencies> <dependency> <groupId>org.mongodb</groupId> <artifactId>bson</artifactId> </dependency> </dependencies>
以下代码片段显示 build.gradle 文件的 dependencies 对象中的依赖声明。
dependencies { compile 'org.mongodb:bson' }
If you are not using one of the preceding tools, you can include it in your project by downloading the JAR file directly from the sonatype repository.