Node12---MongoDB

Source: Internet
Author: User
Tags clear screen ming

* from Step1 where Xingbie = ' female '; for example, query all girls, and age~* from step1 where Xingbie = ' women ' and nianling < 24 and nianling >= and Xianzaisuozaidi = ' Beijing '; the third reason: the database can not play itself, to the PHP,. NET, JSP and other languages to provide interfaces. In PHP these languages, can be deleted from the database and other changes. 
Old database, are structured database, now what is the problem? For example, we now want to add a field "high school information" to a database that already has 1000 data. The previously existing data does not actually need to be added to this field. Because these users have completed the form, no need to re-mobile high school information. Our intention is to register users in the future, need to fill in high school information. But, as we just said, the so-called field is a structure of the table. All rows must be owned, no rows have this field, and some rows do not have this field. It can be imagined that in the era of big data, there are 1 million data in the database are small. If we want to move the field, the time is too long. So, field this thing, too inflexible. Data is not flexible. A field that needs to be the same type of data. Cannot be a row of records is text, a row of records is a number. The non-structured database NoSQL emerges. NoSQL is a freak, unable to challenge the old database, but in the big data age has its own meaning. Second, NoSQL non-structured database. There is no concept of rows or columns. Use JSON to store data. The set that is appropriate for the table structure is equivalent to "table", and the document is equivalent to "row".

The document is JSON, context, is also the JavaScript category, so our database is the JS category of things, JS full stack.

Therefore, we summarize the NoSQL database in the following cases, the comparison is applicable: 1, the data model is relatively simple, 2, the need for more flexible IT systems, 3, the database performance requirements are high, 4, does not require a high degree of data consistency, 5, for a given key, more easily map complex values of the environment.
We see that some systems, in particular, need to be screened. For example, all girls over the age of 20 are screened out. So SQL database, very good at! Because it has the concept of rows and columns. However, some systems do not really need to do so much filtering, such as in-station letters. It is only necessary to store the letter in the station. No filtering is required. Well, NoSQL. NoSQL is not a silver bullet, it is not qualified to challenge an established database, or in a particular case, it is appropriate.
  Three, MongoDB installation official website: https:  // www.mongodb.com/ Manual: Https:// docs.mongodb.org/manual/ win7 system needs to install patches, KB2731284.  At this point, let's look at the loaded folder: C:\Program files\mongodb\server\  3.0\bin Add to the system's PATH environment variable (this is the database file location, not the database location, the database location can be changed) then we can use the MONGO command on any of the system's drive characters: Mongod.exe boot mongo.exe use database Mongoimport . exe import data  
--DBPath  mongedbdata--DBPath is the folder where you select the database document. In other words, MongoDB, there really is a physical file, corresponding to a database. U-Disk can be copied away. Be sure to keep, boot this cmd can't move, can't shut, can't ctrl+C. Once this cmd has a problem, the database shuts down automatically. Therefore, a second cmd should be opened. Input MONGO: Then, the operating environment is MONGO syntax. List all databases: 1show DBS using a database 1use database name if you want to create a new database, use it. Use a non-existent, is new. View current database 1db Insert data: Student is called a collection. There is a lot of JSON stored in the collection. The student is used for the first time, and the collection is created automatically. 
--DBPath C:\mongo Management database: MONGO  (be sure to enter in a new CMD) clear screen: 1cls View all database list 1show DBS use database, create DATABASE 1use itcast If you really want to create this database successfully , you must insert a data. Data cannot be inserted directly into the database, only data can be inserted into the collection (collections). There is no need to create a collection, just write the point syntax: 1db.student.insert ({"Name": "Xiaoming"});d the B.student  system discovers that student is a strange collection name, so the collection is created automatically. Delete the database, delete the current database 1db.dropdatabase ();
 4.1 insert data into the data, as the data is inserted, the database is created successfully, and the collection is created successfully. 1db.student.insert ({ "name": "Xiaoming" }); We cannot insert a single line. So, we want to use sublime to write the form of the database externally, and then import the database: 1mongoimport --db test--collection restaurants--drop--file Primer-dataset.json -db test to which database to import --collection restaurants the collection to which you want to import --drop to Empty the collection --file Primer-dataset.json which file so that we can create a JSON file with sublime and then import it with the Mongoimport command, so it's very convenient to learn the database. MONGO can save objects.  4.2 find data to find data, use Find. There are no parameters in find, then all documents for this collection are listed: 1db.restaurants.find ()  
  exact match: 1db.student.find ({ "Score.shuxue": 70}); // score This JSON Shuxue the value of this key is 70   multiple conditions: 1db.student.find ({ "Score.shuxue": +, "age": 12 }) is greater than the condition: 1db.student.find ({ "Score.yuwen": {$gt: 50  ' age ': 9},{' age ': 11 "borough": 1, "Address.zipcode": 1}) 
 4.3 Modify the data there are also query conditions. Who do you want to tell MONGO. Look for the name named Xiao Ming, change the age to 16 years old: 1db.student.update ({ "name": "Xiao Ming"},{$set: {"" Age ": 16}}); Find the math score is 70, change the age to 33 years old: 1db.student.update ({ "Score.shuxue": 70},{$set: {"old": 33 }}); Change all matching items:  "by default, the update () method updates a single document. To update multiple documents, with the multi option in the update () method. 1db.student.update ({ "sex": "Male"},{$set: {"Age" :33}},{multi:true});   2db.student.update ({},{$set: { "age" :33}},{multi:true}); All changed completely replace, do not appear $set keyword: change xiaoming this record to { "name": "Daming", "Age" :16}1db.student.update ( { "name": "Xiaoming"},{"name": "Daming", "Age": +}); 
4.4"borough": "Manhattan"defaulttrue  }) Mongovue Beta is the MONGO database visualization tool

Database Example:

{"Name": "Xiao Ming", "Age": "Hobby": ["Sleeping", "eating"], "score": {"Yuwen": "Shuxue": "}}{" "Name": "Little Red", "age": 11, " Hobby ": [" Learning "," reading "]," score ": {" Yuwen ": +," Shuxue ":}}{" name ":" Xiao Qiang "," age ": All," hobby ": [" Fight "]," score ": {" Yuwen ": 2," Shuxue ":}}{" name ":" Xiao Chen "," Age ": 9," hobby ": [" Fight "," reading book "]," score ": {" Yuwen ":," Shuxue ": 80}}

Node12---MongoDB

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.