The Windows platform uses a MongoDB shell to connect to a MONGODB server and create a database
- command line into the bin directory of MongoDB run Mongod.exe
mongod --dbpath c:\data\db
Or find the bin directory of MongoDB and double-click Run Mongod.exe. To output I NETWORK [Thread1] waiting for connections on port 27017.
- The command line enters MongoDB's Bin directory to run:
mongo
Open a connection (default is local) when you return to the window where you are running the./mongod command, you can see where the server is connected to MongoDB, and you can see the following information:
2017-09-26T14:53:12.833+0800 I NETWORK [thread1] connection accepted from 127.0.0.1:54114 #1 (1 connection now open)/*该行表明为一个来自本机的连接*/2017-09-26T14:53:12.864+0800 I NETWORK [conn1] received client metadata from 127.0.0.1:54114 conn1: { application: { name: "MongoDB Shell" }, driver: { name: "MongoDB Internal Client", version: "3.4.9" }, os: { type: "Windows", name: "Microsoft Windows 8", architecture: "x86_64", version: "6.2 (build 9200)" } }
The command line interface to return to the input MONGO command is as follows:
Since it is a JavaScript shell, you can run some simple arithmetic operations:
> 2 + 2
4
> 4+4
8
At this point we can create our own database with the following examples:
Look at all the databases, examples are as follows:
> show dbs admin 0.000GB local 0.000GB
This is not to see our new database, we can insert a piece of data to it and view it again
> db.testMongoDB.insert({"name":"新建的数据库"})WriteResult({ "nInserted" : 1 })> show dbsadmin 0.000GBlocal 0.000GBtestMongoDB 0.000GB
- The default database in MongoDB is test, and if you do not create a new database, the collection will be stored in the test database.
The Windows platform uses a MongoDB shell to connect to a MONGODB server and create a database