MongoDB Learning notes-data formats and data types

Source: Internet
Author: User

Json

JSON is a simple way to represent data, it is easy to understand, easy to parse, easy to remember. But on the other hand, JSON has some limitations because there are only a few types of data such as NULL, Boolean, number, string, array, and object. For example, JSON has no date type, JSON has only one numeric type, cannot distinguish between floating-point numbers and integers, let alone 32 and 64-bit numbers. Furthermore, JSON cannot represent other common types, such as regular expressions or functions.

BSON

BSON (binary serialized Document format) is a binary form of a class JSON storage format, referred to as binary JSON. Like JSON, it supports inline document objects and array objects, but Bson has some data types that JSON does not have, such as date and bindata types. It supports the following data types. Each data type corresponds to a number, and in MongoDB you can use the $type operator to view the Bson type of the corresponding document

Type corresponding numbers Alias Description
Double1 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"
Javascript 13 "JavaScript"
Symbol 14 "Symbol"
JavaScript (with scope) 15 "Javascriptwithscope"
32-bit integer 16 "Int"
Timestamp 17 "Timestamp"
64-bit integer 18 "Long"
Min Key -1 "Minkey"
Max Key 127 "Maxkey"

Basic data types

Null: Used to represent a null or nonexistent field, {"X": null}

Boolean: Boolean type has two values of true and false,{"X": True}

Value: The shell uses 64 as a floating-point value by default. {"X": 3.14} or {"X": 3}. For integer values, you can use either Numberint (4-byte symbol integer) or Numberlong (8-byte symbol integer), {"X": Numberint ("3")} {"X": Numberlong ("3")}

String: UTF-8 string can be represented as a string type of data, {"X": "Hehe"}

Date: The date is stored as the number of milliseconds that the epoch relies on, not the time zone, {"X": New Date ()}

Regular Expressions: When querying, use regular expressions as qualifiers, syntax is the same as JavaScript regular expressions, {"X":/[abc]/}

Arrays: Data lists or datasets can be represented as arrays, {"X": ["a", "B", "C"]}

Inline documents: Documents can be nested in other documents, processed as values by nested documents {"X": {"Y": 3}}

Object ID: Object ID is a 12-byte string, which is the unique identifier of the document, {"X": ObjectId ()}

Binary data: Binary data is a string of any byte. It cannot be used directly in the shell. If you want to save non-utf-characters to the database, the binary data is the only way.

Code: Queries and documents can include any JavaScript code, {"X": function () {/*...*/}}

The relationship between BSON and MongoDB

Bson is a document format used to store MongoDB "documents". The driver is used when inserting, querying, or other operations with the document. The document is encoded in Bson format and then sent to the server. Similarly, when the server returns the document to the client, it is also in the Bson format. The driver first decodes this bson and then passes it on to the client. Thus, the relationship between Bson and MongoDB is: MongoDB uses Bson format to store data and transmit data

Source : http://www.cnblogs.com/Khadron/p/MongoDB_Note_1.html

MongoDB Learning notes-data formats and 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.