command to start the database
1 |
mongod --dbpath C:\MongoDb\data\db -logpath C:\MongoDB\data\log\mongolog.log |
Common commands for several databases
use DATABASE_NAME // 创建数据库
>db // 检查当前的数据库
mydb
>show dbs // 查询数据库列表
local 0.78125GB
test 0.23012GB
db.dropDatabase(‘mydb‘)
Create a collectionMongoDB's
db.createcollection (name, options)used to create a collection
nameis the name of the collection to create
Optionsis a document that specifies the configuration of the collection
capped |
boolean |
(optional) If true, it enables the upper bound collection. The upper bound collection is a fixed-size collection that automatically overwrites the oldest entries when it reaches its maximum size. If you specify true, you also need to specify the size of the parameter. |
autoindexid |
boolean |
(optional) If true, the index _id field is created automatically. The default value is False. |
size |
number |
(optional) specifies the maximum size of the upper collection byte. If capped is true, you also need to specify this field. |
Max |
Number |
Optionally, specify the maximum number of files allowed for the upper bound collection. |
Show All Collections
show collections
>db.mycol.find()
>db.mycol.find().pretty()
Delete Collection
DB.collection_name.Drop()
the RDBMS WHERE clause is equivalent to MongoDBConditional query
db.mycol.find({‘age‘:{$gte:20}}).pretty()
Mainly the usage of several keywords < $lt <= $lte > $gt >= $gte = Do not write! =!! = $ne
From for notes (Wiz)
Database-mongodb-Common Commands