官术网_书友最值得收藏!

  • Mastering MongoDB 3.x
  • Alex Giamas
  • 152字
  • 2021-08-20 10:10:49

Data types

MongoDB uses BSON, a binary-encoded serialization for JSON documents. BSON extends on JSON data types offering for example, native date and binary data types.

BSON, compared to protocol buffers, allows for more flexible schemas that come at the cost of space efficiency. In general, BSON is space efficient, easy to traverse, and time-efficient in encoding/decoding operations.

MongoDB Documentation https://docs.mongodb.com/manual/reference/bson-types/

In MongoDB, we can have documents with different value types for a given field and distinguish among them in querying using the $type operator.

For example, if we have a balance field in GBP with 32-bit integers and double data types, if the balance has pennies in it or not, we can easily query for all accounts that have a rounded balance with any of the following queries:

db.account.find( { "balance" : { $type : 16 } } );
db.account.find( { "balance" : { $type : "integer" } } );
主站蜘蛛池模板: 大关县| 扶绥县| 东方市| 黄石市| 姜堰市| 巴林右旗| 石首市| 呈贡县| 高陵县| 辉县市| 丰镇市| 汉沽区| 四会市| 调兵山市| 岗巴县| 曲水县| 汝阳县| 澄迈县| 务川| 东丽区| 普兰店市| 乳山市| 洪江市| 温宿县| 稷山县| 宝清县| 宁德市| 海伦市| 巴南区| 民丰县| 玉屏| 黎城县| 仁化县| 鄂托克前旗| 连云港市| 余干县| 星子县| 盘山县| 兴化市| 和平区| 宜良县|