The most basic command of MongoDB is to scan your notes

  • 2020-05-15 02:28:32
  • OfStack

After installation, enter in the console:

mongo starts the client.

show dbs displays all databases.

use xxx selects the database as the one currently in use.

show collections displays all collections of the current database.

db.colleciton.find () to find all the data for the table.

db.serverStatus () checks the status of the database server.

db.stats () queries the statistics for the specified database.

use xxx creates a database if the database does not exist (must insert 1 data)

db.storeCollection.insert ({'version':'13', 'segment':'456'}) inserts data while creating the collection

db.dropDatabase () deletes the database

db.mycoll.drop () removes the collection

db.storeCollection.save ({'version':'3.5', 'segment':'e3ol6'}) update the record

db.storeCollection.remove ({'version':'3.5'}) deletes the record

db.page.ensureIndex ({'title':1, 'url':-1}) create index, 1 in positive order, -1 in reverse order

Index established by db.page.getIndexes () query

db.mycoll.dropIndex (name) drop the index, if no arguments are taken, drop all the indexes

db.baseSe.reIndex () rebuild the index

db.baseSe.storageSize () queries the available storage space for a collection of specified databases

db.baseSe.totalSize () queries the allocated storage space of the collection

PS: unable to start problem after abnormal shutdown
When I was about to restart mongoDB, I found that it was not working. The error message is as follows:


Tue Apr 17 11:13:30
Tue Apr 17 11:13:30 warning: 32-bit servers don't have journaling enabled by default. Please use --journal if you want durability.
Tue Apr 17 11:13:30
Tue Apr 17 11:13:30 [initandlisten] MongoDB starting : pid=7128 port=27017 dbpath=D:\Programs\mongodb204\db 32-bit host=FALCON
Tue Apr 17 11:13:30 [initandlisten]
Tue Apr 17 11:13:30 [initandlisten] ** NOTE: when using MongoDB 32 bit, you are limited to about 2 gigabytes of data
Tue Apr 17 11:13:30 [initandlisten] **    see http://blog.mongodb.org/post/137788967/32-bit-limitations
Tue Apr 17 11:13:30 [initandlisten] **    with --journal, the limit is lower
Tue Apr 17 11:13:30 [initandlisten]
Tue Apr 17 11:13:30 [initandlisten] db version v2.0.4, pdfile version 4.5
Tue Apr 17 11:13:30 [initandlisten] git version: 329f3c47fe8136c03392c8f0e548506cb21f8ebf
Tue Apr 17 11:13:30 [initandlisten] build info: windows sys.getwindowsversion(major=6, minor=0, build=6002, platform=2, service_pack='Service Pack 2')BOOST_LIB_VERSION=1_42
Tue Apr 17 11:13:30 [initandlisten] options: { dbpath: "D:\Programs\mongodb204\db" }
**************
Unclean shutdown detected.
Please visit http://dochub.mongodb.org/core/repair for recovery instructions.
*************
Tue Apr 17 11:13:30 [initandlisten] exception in initAndListen: 12596 old lock file, terminating
Tue Apr 17 11:13:30 dbexit:
Tue Apr 17 11:13:30 [initandlisten] shutdown: going to close listening sockets...
Tue Apr 17 11:13:30 [initandlisten] shutdown: going to flush diaglog...
Tue Apr 17 11:13:30 [initandlisten] shutdown: going to close sockets...
Tue Apr 17 11:13:30 [initandlisten] shutdown: waiting for fs preallocator...
Tue Apr 17 11:13:30 [initandlisten] shutdown: closing all files...
Tue Apr 17 11:13:30 [initandlisten] closeAllFiles() finished
Tue Apr 17 11:13:30 dbexit: really exiting now

Solutions:
1. Delete the.lock file under %MONGO_HOME%/db

2. Enter the command mongod --repair

3. Restart mongoDB


Related articles: