Install MongoDB
- Installation
- configuration environment variable (novice recommend using the default installation path)
C: \ Program Files \ MongoDB \ Server \ 3.2 \ bin
- in the root directory of c
- Create a folder data
- to create a data file in the folder db
- Open cmd command line window
- input mongod start mongodb server
- 32 Note:
when starting a server, need to enter the following
mongod --storageEngine = mmapv1
mongod database path --port port number --dbpath
- In open another window cmd - input connected MongoDB mongo, appeared> - Database (Database) - database server - the server to store data - used to start the mongod server - client database - Client to server operating on data CRUD operations - to enable the client Mongo - MongoDB to the service system can automatically started in the background, you do not need to manually start every time 1. Create a root directory data in c - creating data in DB and log folders 2. create a configuration file in the directory C: \ Program files MongoDB \ \Server adds a lower profile \ mongod.cfg 3. open a command line window as an administrator 4. Run the following command
sc.exe create MongoDB binPath= "\"C:\Program Files\MongoDB\Server\3.2\bin\mongod.exe\" --service --config=\"C:\Program Files\MongoDB\Server\3.2\mongod.cfg\"" DisplayName= "MongoDB" start= "auto" sc.exe create MongoDB binPath= "\"mongod的bin目录\mongod.exe\" --service --config=\"mongo的安装目录\mongod.cfg\"" DisplayName= "MongoDB" start= "auto" 我本机的mongo的bin目录:C:\Program Files\MongoDB\Server\4.2\bin C:\Program Files\MongoDB\Server\4.2 sc.exe create MongoDB binPath= "\"C:\Program Files\MongoDB\Server\4.2\bin\mongod.exe\" --service --config=\"C:\Program Files\MongoDB\Server\4.2\mongod.cfg\"" DisplayName= "MongoDB" start= "auto"
5. Start mongodb service (my operations are found in the windows 'service' in MongoDB, then select the service, click start)
6. If it fails to start, proved the top of a mistake,
enter the service sc delete MongoDB delete previously configured in the console
and then again from the first step
- Basic concepts of
database (database)
collection (collection)
document (the Document)
- in MongoDB, databases and collections do not need to manually create,
when we create a document, if the document where the collection or database does not exist will automatically create the database and collections
- basic instructions
Show DBS
Show databases
- displays the current database of all
use the database name
- into the specified database
DB
- DB indicates the database is currently located
Show collections
- Show all collection database
- the database of the CRUD (CRUD check) operation
- into the document into the database
DB <collection> .insert (DOC).
- inserting a document to the collection
- examples: inserted into the test database, stus set a new target student
{name: "Monkey ", age: 18, gender: " male "}
db.stus.insert ({name: "Monkey", age: 18, gender: " M"})
. DB <Collection> .find ()
- to query all documents in the current collection