mongodb基本命令行操作

mongodb创建数据库
use dbname
mongodb查看数据库
show dbs
查看数据库下面的表
show collections
查询表里的数据
db.表名.find()
mongodb向表里插入一条数据
./mongofiles -d campus put readme.txt
根据条件查询表里的数据
db.表名.find({‘key’:‘value’})
修改表里的某个字段
db.user.update({“age”:“21”},{$set:{“name”:“aaaaabbb”}});
mongodb基本命令行操作_第1张图片

Last login: Mon Nov 21 15:16:39 2016 from 117.101.170.60

Welcome to aliyun Elastic Compute Service!

[root@iZ25i85s0laZ ~]# ./mongo
-bash: ./mongo: No such file or directory
[root@iZ25i85s0laZ ~]# bin
-bash: bin: command not found
[root@iZ25i85s0laZ ~]# cd /mongodb/mongodb/bin
[root@iZ25i85s0laZ bin]# ./mongo
MongoDB shell version: 2.4.9
connecting to: test

shoeshowshoshs;lklk;k;k;lk;lklk;k;k;lk
Mon Nov 21 16:51:39.410 ReferenceError: lklk is not defined
show dbsshow dbs
admin (empty)
cdb_dev 0.953125GB
cdb_test_dev 0.453125GB
dd_dev 0.453125GB
isb_dev 0.953125GB
local 0.078125GB
use capuse cafmkdlndkluse cafmkdlndkl
switched to db cafmkdlndkl
use campususe campus
switched to db campus
show dbs;show dbs;
admin (empty)
cdb_dev 0.953125GB
cdb_test_dev 0.453125GB
dd_dev 0.453125GB
isb_dev 0.953125GB
local 0.078125GB
use campususe campus
switched to db campus
qq
Mon Nov 21 16:56:25.971 ReferenceError: q is not defined
^C
bye
[root@iZ25i85s0laZ bin]# ls
bsondump mongo mongod mongodump mongoexport mongofiles mongoimport mongooplog mongoperf mongorestore mongos mongosniff mongostat mongotop
[root@iZ25i85s0laZ bin]#
[root@iZ25i85s0laZ bin]# ll
total 237560
-rwxr-xr-x 1 srx srx 18294928 Jan 10 2014 bsondump
-rwxr-xr-x 1 srx srx 9535400 Jan 10 2014 mongo
-rwxr-xr-x 1 srx srx 18348264 Jan 10 2014 mongod
-rwxr-xr-x 1 srx srx 18352336 Jan 10 2014 mongodump
-rwxr-xr-x 1 srx srx 18307248 Jan 10 2014 mongoexport
-rwxr-xr-x 1 srx srx 18356384 Jan 10 2014 mongofiles
-rwxr-xr-x 1 srx srx 18319472 Jan 10 2014 mongoimport
-rwxr-xr-x 1 srx srx 18298992 Jan 10 2014 mongooplog
-rwxr-xr-x 1 srx srx 18298992 Jan 10 2014 mongoperf
-rwxr-xr-x 1 srx srx 18357712 Jan 10 2014 mongorestore
-rwxr-xr-x 1 srx srx 13862296 Jan 10 2014 mongos
-rwxr-xr-x 1 srx srx 18262728 Jan 10 2014 mongosniff
-rwxr-xr-x 1 srx srx 18344432 Jan 10 2014 mongostat
-rwxr-xr-x 1 srx srx 18298992 Jan 10 2014 mongotop
[root@iZ25i85s0laZ bin]# toch readme.txt
-bash: toch: command not found
[root@iZ25i85s0laZ bin]# touch readme.txt
[root@iZ25i85s0laZ bin]# ls
bsondump mongo mongod mongodump mongoexport mongofiles mongoimport mongooplog mongoperf mongorestore mongos mongosniff mongostat mongotop readme.txt
[root@iZ25i85s0laZ bin]# echo “init campus db” > readme.txt
[root@iZ25i85s0laZ bin]# cat readme.txt
init campus db
[root@iZ25i85s0laZ bin]# ./mongofiles -d campus put readme.txt
connected to: 127.0.0.1
added file: { _id: ObjectId(‘5832b7b4092e24e9a405e58b’), filename: “readme.txt”, chunkSize: 262144, uploadDate: new Date(1479718836988), md5: “1edb3f38324aa6b503e6de6c9e53cf60”, length: 15 }
done!
[root@iZ25i85s0laZ bin]# ./mongo
MongoDB shell version: 2.4.9
connecting to: test
show dbs;show dbs;
admin (empty)
campus 0.203125GB
cdb_dev 0.953125GB
cdb_test_dev 0.453125GB
dd_dev 0.453125GB
isb_dev 0.953125GB
local 0.078125GB
use campusluse campusl
switched to db campusl
use campus;use campus;
switched to db campus
show tables;show tables;
fs.chunks
fs.files
system.indexes
db.fs.files.find()db.fs.files.find()
{ “_id” : ObjectId(“5832b7b4092e24e9a405e58b”), “filename” : “./readme.txt”, “chunkSize” : 262144, “uploadDate” : ISODate(“2016-11-21T09:00:36.988Z”), “md5” : “1edb3f38324aa6b503e6de6c9e53cf60”, “length” : 15 }
db.fs.chunks.find()db.fs.chunks.find()
{ “_id” : ObjectId(“5832b7b400886d5ba33316f2”), “files_id” : ObjectId(“5832b7b4092e24e9a405e58b”), “n” : 0, “data” : BinData(0,“aW5pdCBjYW1wdXMgZGIK”) }

你可能感兴趣的:(数据库)