Basic data types and the basic concept of mongodb

The basic data types
  MongoDB file storage format BSON, as with other documents to support JSON array of objects and re-insert the document objects and arrays, while extending the JSON data types. Those dealing with the application database. For example, JSON no date type, which would make otherwise simple issue date processing becomes very complicated. Only a digital type, can not distinguish between integers and floating-point, but can not distinguish between 32-bit and 64-bit number. There is no way represent other common types, such as regular expression or function.
  The supported data types MongoDB:
 null null field for indicating a null value or does not exist. { "x": null}
Boolean Boolean type has two values 'true' and 'false1' { "X-":} to true.
32-bit integer type is not available. JavaScript only supports 64-bit floating-point, so 32-bit integer will be converted automatically.
64-bit integer does not support this type. shell uses a special embedded documents to display 64-bit integer,
digital 64-bit floating-point numbers in the shell are of this type. The following floating-point representation is: { "X": 3.1415926} { "X": 3}
string UTF-8 strings can be expressed as a string data type: { "x": "foobar "}
symbols are not this type of support. converting the shell database symbols to a string type.
Object Object id id is a unique document ID 12 bytes, { "X": ObjectId ( )}
Date Date type is stored in a standard number of milliseconds from the start of the era. When the storage area is not: { "
Regular expressions document may comprise a regular expression, using JavaScript regular expression syntax: { "x": / foobar / i}
documentation in the code may also contain JavaScript code: { "x": function ( ) {/ * ... ... * /}}
binary data of binary data may consist of arbitrary byte strings. But you can not use the shell.
BSON comprises a maximum of special type, indicates the maximum possible. shell does not have this type.
BSON include a special type of minimum represents the minimum possible. shell does not have this type.
Documents can also be used undefined undefined type: { "x": undefined}
set or list of values can be expressed as an array of arrays: { "x": [ " a", "b", "c"]}
inline document document may contain other document may be embedded as the value of the parent document, the data can be organized more natural, do not have to keep a flat structure: { "x": { " food": "noodle"
 
}} Digital
  JavaScript only one of "digital" type. Because there are three kinds of digital MongoDB type (32-bit integer, 64-bit integer and 64-bit floating-point number), the shell must be bypassed to limit the JavaScript. By default, the numbers are MongoDB shell as a double precision number. This means that if you get from the database is a 32-bit integer, the revised document, the document is stored back in time to the database, the integers are converted into floating-point, integer intact will even keep this case. So it is wise to avoid covering the entire document in the shell.
date
  When JavaScript Date object date type used MongoDB to create a new Date object, usually invokes new Data ( "").
 
 
The basic concept
will be described as similar to learning RDMS first row, the table, the concept of the knowledge database, and then to learn CRUD operations.
1. Document
  the document is the basic unit of data in MongoDB (similar row in a relational database, but much more complex than a line). Multiple keys and values associated with the document is put together in an orderly manner. MongoDB file storage format BSON.
  BSON is short for Binary JSON, JSON document object is a binary coded format. BSON Like other documents to support JSON array of objects and re-insert the document objects and arrays, while extending the JSON data types. Such as: BSON Date type and have BinDate type. BSON has three characteristics: lightweight, can be ergodic, efficient
  document can be so expressed:
  { "firstName": "Egger", "lastName": "Wong"}
  Note points:
 the document key / value pair is sequence.
The value of the document can not only be a string in double quotes can also be several other data types (can even be embedded throughout the document).
MongoDB differentiate the type and sensitive.
MongoDB document can not have duplicate keys.
Key document is a string. With few exceptions, the key may be any UTF-8 characters.
 Key can not contain \ 0 (null character). This character is used to indicate the end of the bond.
.
Underscore "_" at the beginning of keys are reserved (not strictly required).
2. collection
  collection is a set of documents (similar to relational database tables), can be seen as a table without a schema.
  No pattern
  set is no pattern. This means that a set of documents which may be widely varied. For example, the following two may exist in the same document set inside:
  { "name": "Egger"}
  { "Age":} 18 is
  above documents is not only different types of values (integers and strings), they are also the key completely different.
  Although the collection can be placed inside any document, but it is recommended to use multiple sets:
 the kinds of documents are mixed in a collection inside, both for the developer or administrator is a nightmare.
Query a specific type of document in a collection which is very worthwhile in terms of speed, do separate multiple collections much faster.
The same types of documents in a collection where this data will be more concentrated.
When creating an index, the document will be additional structures (especially when the only index). The index is defined in accordance with the set. The same types of documents into the same collection which can make the index more effective. 
  Naming
  we can identify the collection by name. Name can be set to satisfy any of the following conditions UTF-8 string.
 Collection name can not be empty string "."
Collection name can not contain \ 0 character (null character), this character represents the end of the collection name.
Collection name can not be "system." At the beginning, which is the prefix for the collection system reserved.
User-created collection name can not contain reserved characters. Some drivers do support included in the set name inside. Some drivers do support included in the set were there, this is because the collection contains some system-generated character. Unless you want to access this collection created by the system, or do not appear in $ name inside. 
  A subset of
  a practice is the use of tissue collection. "" Namespace is divided by a subset of characters separated. Subset used to organize data in MongoDB is a good way
  for example, personal information may include a set of two, respectively, and person.name person.age. This is done just to make the organization better, that person this collection (here simply do not need to exist) and its subset nothing to do. The name of the database collection name to the front, is a collection of fully qualified name, known as a namespace. Namespace length not more than 121 bytes, in actual use should be less than 100 bytes.
  Many MongoDB tools are included in the subset.
 GridFS is a protocol store large files using a file to store a subset of metadata, so that the content blocks separated
MongoDB Web console subset of the data is organized in a manner DBTOP portion.
Vast majority of drivers provide syntactic sugar, as specified subset of the set of access with ease.
3. Database
  MongoDB database may be composed of a plurality of sets. MongoDB single instance can accommodate a plurality of individual databases, each with its own set of permissions and, different databases are also placed in different files.
  Database also be identified by name. Database name may be any of the following conditions are UTF-8 string.
 It can not be an empty string ( "").
Contain not '' (blank),., $, /, \, And \ 0 (null character Yu).
It should be all lowercase.
Up to 64 bytes.
  Some database names are reserved and can directly access these databases have a special role.
• admin
from the point of view of authority, which is the "root" database. If a user is added to the database, the user automatically inherits all the permissions database. Some specific server-side command can only be run from the database, such as a list of all database or server.
• local
This data will never be copied, can be used to store a local limited to any single server set
• config
when Mongo provided for fragmentation, config databases use for storing fragmentation related information.
Published 19 original articles · won praise 3 · Views 9771

Guess you like

Origin blog.csdn.net/pinghuqiuyue9/article/details/50949839