mongodb基础

启动mongodb(默认会连到test)

cangxian@cangxian-CN17S:~$ mongo
MongoDB shell version: 2.4.9
connecting to: test

查看所有的库

> show dbs;
db	(empty)
ldblog	0.203125GB
local	0.078125GB
test	0.203125GB

查看当前库

> db;
test

调用库(如果不存在则会创建)

> use newTestDB;
switched to db newTestDB

创建集合(同sql表)

> db.createCollection("testCollection");
{ "ok" : 1 }

查看所有的集合

> show tables;
system.indexes
testCollection

向集合中插入测试数据(同样如果这个集合不存在会创建新的集合在插入数据)

> db.testCollection.insert({"name" : "testCollection"});

查询集合

> db.testCollection.find();
{ "_id" : ObjectId("5a2d3b8e01418fe4d753f463"), "name" : "testCollection" }

删除集合

> db.createCollection("testDeleteCollection");
{ "ok" : 1 }
> db.testDeleteCollection.drop();
true

删除表

> use testDeleteDB;
switched to db testDeleteDB
> db.dropDatabase();
{ "dropped" : "testDeleteDB", "ok" : 1 }
> show tables;
> show dbs;
db	(empty)
ldblog	0.203125GB
local	0.078125GB
newTestDB	0.203125GB
test	0.203125GB
testDeleteDB	(empty)

 

转载于:https://my.oschina.net/liangguoqiang/blog/1587606

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值