Introduction to MongoDB data types

Source: Internet
Author: User
Tags deprecated

Refer to MongoDB website: https://docs.mongodb.com/manual/reference/bson-types/

The MongoDB document store is using the BSON type, BSON (BSON short for bin-ary JSON, is a bin-ary-en-coded seri-al-iz-a-tion of Json-like Doc-u-men TS) is a binary serialization format. Classes, such as JSON, also support inline various types.

  

Number
Type Alias Notes
Double 1 "Double"
String 2 "String"
Object 3 "Object"
Array 4 "Array"
Binary data 5 "Bindata"
Undefined 6 "Undefined" Deprecated.
ObjectId 7 "ObjectId"
Boolean 8 "BOOL"
Date 9 "Date"
Null 10 "NULL"
Regular Expression 11 "Regex"
Dbpointer 12 "Dbpointer" Deprecated.
Javascript 13 "JavaScript"
Symbol 14 "Symbol" Deprecated.
JavaScript (with scope) 15 "Javascriptwithscope"
32-bit integer 16 "Int"
Timestamp 17 "Timestamp"
64-bit integer 18 "Long"
Decimal128 19 "Decimal" New in version 3.4.
Min Key -1 "Minkey"
Max Key 127 "Maxkey"

Several types are highlighted,

Objectid type: This is the only key that MongoDB generates like a relational DB table primary key, generating fast. This is made up of 12 bytes:

The first 4 bytes are unix seconds, 3 bytes of machine identifiers (for distributed primary keys are unique), 2 bytes of process id,3 bytes of counter number

    • A 4-byte value representing the seconds since the Unix epoch,
    • A 3-byte machine identifier,
    • A 2-byte process ID, and
    • A 3-byte counter, starting with a random value.

MongoDB was designed to be a distributed database. From the generation of the Objectid unique primary key, it deserves the reference of the Distributed System Designer.

A 3-byte machine identifier representing the different machine on which the MongoDB instance resides, and a 2-byte process ID representing a different MongoDB instance of the same machine. Plus a timestamp and a random number (3 bytes random number, the same second, theoretically can have 2^24), to a large extent, to ensure the uniqueness of the Objectid.

Introduction to MongoDB data types

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.