MongoDB's study [three]: MongoDB architecture

1, the comparison logic
 
relational database: mysql database (Database), table (Table), records (rows) of the composition of the concept of three levels. 
Non-relational databases: MongoDb database (database), collection (collection), (document) the concept of three levels of document objects. 

MongoDB in the corresponding set of MySQL tables, but the collection is not listed, conceptual row and relationships, set only a document, a document equivalent to a record, this is the show features free mode.


2, the data storage structure
 
data storage structure Mysql of:
storing data in Mysql, is placed in a directory with the same name in the database, if you use MyISAM engine, directory data will appear in .frm, MYD, MYI file. 

MongoDB data storage structure:
MongoDB default data directory is / data / db, which is responsible for storing all of MongoDB data files. In MG, each database contains a .ns files and data files, and that these data files will increase the amount of data becomes increasingly more. If there is a fruit of the database, the database constitutes the document has fruit.ns, fruit.0, mydb.1 three files.

MongoDB tips: 
See all the databases show dbs 
view the current database db 
view the current database in the number of collections show tables or the Collections Show 3, MongoDB data type 
MongoDB bson use to organize data, bson similar json, json just a simple data representing the embodiment, there are six kinds of data (null, boolean, numeric, string, and an array of objects) can not fully meet the needs of a complex business, therefore, also provides BSON date, 32-bit number, 64-bit number, and other types . 
A, Null 
null null values for indicating the type or the absence of a field, such as: { "One": null} 
B, boolean 
true or false, or 1 and 0 can be expressed as: { "one": true} 
C, 32-bit integer 
mongoDB console input using JS engine, and JS only supports 64-bit floating-point, so 32-bit integer will automatically be escaped. 
D, 64-bit integer 
64-bit and 32-bit integer as MongoDB console when using 64-bit floating-point number will escape. 
e, 64-bit floating point 
default type MongoDB console numbers. Such as: { "One": {2.02} "One": 10} 
F, string 
UTF-8 can be expressed as a string data type string. The { "One": "the Hello, Jean"} 
G, the symbol 
does not support this type MongoDB console will automatically escape of type string. 
h, ObjectId type












Document object id is unique 12-bit ID. 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11, i.e., the timestamp | machines | the PID | counter. 

i, date 
Note: When used to add new new, such as { "One": new new a Date ()} 

J, regular expressions 
document may comprise a regular expression, which uses regular expression syntax represented JS. Such as: { "One": / HO / I} 

K, the code 
in the document may contain js code, such as { "One": function () {}} /*..........*/ 

L, array 
document key may be expressed as an array, the array may be embedded in an array, such as: { "x": [ " a", [ "o", "j", [ "x", "y", "Z"]]]} 

m, embedded documents 
in the document may contain other document may be embedded as the value of the parent document. 
Such as: { "X": { "name": "Tom", "Sex": "Meal", "Age": 25, "Love": "Beauty"}} MongoDB common commands 
a view database is currently located db 
2, view the list of users db.system.users.find () 
3, the users view all users Show 
4, to see all the databases dbs Show 
5, to see all the collections of the collection Show 
6, delete the current database db.dropDatabase () 
7, delete the set of db. collectionname .drop () 
8, I would like to know which commands help mongo support




 
9, want to know which method the current database support db.help ()
10, want to know what the current collection method supported:. Db collection name .help () 
more commands can be viewed with the help MongoDB common operations. 
1, lists the current database show dbs, the initial state, only admin, local 2 Ge database. 
2, define a new database name use mydb. In fact, this action does not really set up, only that in the current database. 
3, the data saved, defines a collection (set), then insert the data, inserting data using the following statement: 
db.users.insert ({ "_ ID":. 1, "name": "Mongo"}) 
after successful insertion, see All libraries, more than a mydb library, and then view all collections, a collection of more users, and then just add the data view, but also can be found. 
4, add data, insert keywords or save, the basic syntax is as follows: 
db.collname.insert ({...}) 
db.collname.save ({...}) 
> A = { "name": " CAIDA "} {" name ":" WANA "} 
> B = {" Age ": {24}" Age ": 29} 
> db.users.insert (A) 
> db.users.save (B) 
. 5, deleted data, keyword remove, syntax is as follows: 
. 6, modify the data, using the keyword update, the following syntax: 
db.collname.update ({ condition})




 
db.collname.remove (condition) [Note: If you do not write this condition, is to delete all the data]
Example: db.users.remove ({ "name": "badGuy"}) 
Example: db.users.update ({ "_ id" : 1}, { "name", "nosql"}) 
and remove the same, the first parameter which is matched condition, otherwise, it will be possible to modify all the data out. 
7, data query, or find the findOne keyword (a query), the following example: 
db.users.find () to query all data] [ 
db.users.findOne () [] query a data record
Published 59 original articles · won praise 2 · Views 5585

Guess you like

Origin blog.csdn.net/LDR1109/article/details/100945099