Data is the same for each front-end staff must contact all the back-end data are written, if they want to practice project, but there is no data, but to write some fake data, to write, or to build a data through json-server, today we'll set up by a real database MongoDB, from installation to configuration to write, in one step, but also small series installation configuration process, encountered, install the following step, step by step, I believe you will successful
What is MongoDB?
MongoDB is written in C ++ language, it is an open source database distributed file system based storage.
In the case of high load, add more nodes, you can ensure server performance.
MongoDB is designed to provide scalable, high-performance data storage solution for WEB applications.
MongoDB the data is stored as a document data structure of the key (key => value) pairs. MongoDB document similar to JSON object. Field value can contain other documents,
Next Xiaobian take you step by step through the installation and configuration
1. Install MongoDB
Download directly open the package to run after installation, the installation package in a location they want to put, this installation package is on the G drive
Download https://www.mongodb.org/dl/win32
Next has been implementing the next step, when entering this interface, the following √ must be removed, particularly slow or will be installed, if not removed, it may take more than a few hours, small series have been personally tested the
When the value of all the steps completed, find the directory you installed, there will be the following results, (playing small series of mosaics that, do not bother, will not be affected, only small series of the installation package also put this up)
2. environment variable configuration
When MongoDB After installation, you need to configure the environment variables,
The right mouse button to select "Computer" "Properties", a box will pop up, click on the "Advanced System Settings" will pop up a system properties, environment variables found
Find inside this system variable path, click Edit
Find the directory of your installation, be sure to enter the bin directory, this directory are copied to the variable value inside the back to add a ";" and then click OK, this environment variable has been configured
3. Create a database file storage location
In your data directory, create a db file G: \ mongodb \ data \ db
Because of the need to store the file must be created before you start the database file folder mongodb service, otherwise the command does not automatically create, and can not start successfully
4. Start the MongoDB service
1. Open the cmd command patrol with Windows + R key to open, enter cmd
2. Enter the G drive, which is your installation directory, g: \ mongodb \ bin; (be sure to enter the G drive, cd to make your directory cd mongodb, then this cd bin directory)
3. Enter the following command to start MongoDB, mongod --dbpath g: \ mongodb \ data \ db, this is your installation directory and press Enter
That is to start the database stored in the file path created by the third step. When you hit enter when it appears interface, explained that it had succeeded
4. Enter the browser to http: // localhost: 27017, if the following occurs in the browser for some English shows a success
5, configuration windows mongodb local service
This is set to boot from the start, can be directly started manually closed to start the command line net start MongoDB. This configuration will greatly facilitate. Do not start in the directory into the bin
1. create a new folder in the data log file (used to store log files)
2. mongodb New Profile mongo.config, and this is the bin directory at the same level
3. The use Notepad to open mongo.config, and enter the following two commands, then save
dbpath=G:\mongodb\data\db
logpath = G: \ mongodb \ data \ log \ mongo.log mongo.log This automatically generated
4. Open cmd as an administrator, the administrator upper left corner there will be three words, then a G into the directory of your bin: \ mongodb \ bin, this must have administrator's identity to open, or execute the following command It would have been an error
Input: mongod -dbpath "g: \ mongodb \ data \ db" -logpath "g: \ mongodb \ data \ log \ mongo.log" -install -serviceName "MongoDB", MongoDB is to start name
If you enter a command error, then twice, first remove the service sc delete MongoDB, enter the command again just fine
In this case, mongodb Windows service has been configured, we can not enter the bin directory to start the MongoDB,
When we start by entering net start MongoDB I reported this error,
Solution
In mongodn> data> db find this directory, delete the file mongodb.lock,
After you delete this file, run the command again net start MongoDB, has been able to start the service, indicating that MongoDB has been configured
We can enter services.msc command in the command window, a pop-up window service, you can start to see the MongoDB service in
Six commonly used commands
net start MongoDB open service
net stop MongoDB shut down service
ESTABLISHING a database table
After the above configuration, we can build a database of their own, just follow the steps above to step by step, will be successful, Xiao Bian also stepped on a lot of pits, summed up,
Establish a database of commonly used commands, these commands must remember
In the bin directory, enter mongo start, start writing data content
show dbs displays all the current data, we can see, there is no current data content
use students to create a database name, students name of the database
Displays the current database db
show collections to display all of the collection database
db. <collection> .insert (doc) into a document to the database
db.students.insert ({id: "001", name: "JIM", age: "18"}); this is what we inserted data
db.students.find () data by this command, the database query to students currently in the collection of all the documents, you can also query conditions
These are all content today, they would be built from the data, does something, if you like, you can look at the installation process if you have questions, you can shout, and you easily answer
My blog is about to be synchronized to Tencent cloud + community, inviting all of them settled: https://cloud.tencent.com/developer/support-plan?invite_code=281wsnsiy2dcs