Docs Home / mongosh / Reference

EJSON

MongoDB uses BSON, a binary serialization format, to store documents and to exchange data. MongoDB使用二进制序列化格式BSON来存储文档和交换数据。BSON is a rich format and has data types that aren't included in the JSON standard. BSON是一种丰富的格式,其数据类型不包含在JSON标准中。Extended JSON (EJSON) adds support for the additional types. EJSON is a JSON compatible way to represent BSON values.扩展JSON(EJSON)增加了对其他类型的支持。EJSON是一种与JSON兼容的方式来表示BSON值。

mongosh exposes the EJSON interface from the Node.js BSON parser to help you transform your data. Use the EJSON interface when you need to transform BSON data.mongosh公开了Node.js-BSON解析器EJSON接口,以帮助您转换数据。当您需要转换BSON数据时,请使用EJSON接口。

EJSON Method方法Use
EJSON.deserialize()Convert Extended JSON objects to BSON objects. This method is useful to import JSON data from external applications.将扩展JSON对象转换为BSON对象。此方法对于从外部应用程序导入JSON数据非常有用。
EJSON.stringify()Convert BSON objects to strings. This method is useful to transform mongosh output.将BSON对象转换为字符串。这种方法对转换mongosh输出很有用。
EJSON.serialize()Convert BSON objects to Extended JSON representation as JavaScript objects. This method is useful to export JSON data for external data transformation applications.将BSON对象转换为JavaScript对象的扩展JSON表示。此方法对于导出外部数据转换应用程序的JSON数据非常有用。
EJSON.parse()Convert strings to JSON. This method is useful to transform inputs.将字符串转换为JSON。此方法可用于转换输入。

For additional EJSON capabilities, see the npm EJSON documentation.有关其他EJSON功能,请参阅npm EJSON文档

Learn More了解更多

BSON specification规范文档