Mongodb学习笔记——Collections

来源:未知 责任编辑:责任编辑 发表时间:2014-05-20 18:34 点击:
Mongodb学习笔记--Collections
 
MongoDB中的collections就是一系列 BSON documents的集合,相当于关系数据库中的表。
 
collection将会在第一次往里面插入documents时创建
 
> show dbs;
admin    (empty)
foo    0.0625GB
fucker    0.0625GB
local    (empty)
test    0.0625GB
> use fucker;
switched to db fucker
> show collections;
fucker  www.2cto.com  
system.indexes
users
> db.test.insert({"id" : 1 });
> show collections;
fucker
system.indexes
test
users
collection应该以字母或下划线开头,当然数字也是被允许包含在collection名字内的($为保留字符,不可用于命名)。
collection名最大长度为128个字符,建议不要超80/90个字符
 
可以使用如下命令来创建collection(一般用于创建Capped collections)
 
> show collections;
fucker  www.2cto.com  
system.indexes
test
users
> //mongo shell
> db.createCollection("mycoll",{capped:true, size:100000}) //size is in bytes
{ "ok" : 1 }
> show collections;
fucker
mycoll
system.indexes
test
users
或者使用如下方法
 
> show collections;
fucker
mycoll
system.indexes
test
users
> db.runCommand( {create:"mycoll_1", capped:true, size:100000} )
{ "ok" : 1 }
> show collections;
fucker  www.2cto.com  
mycoll
mycoll_1
system.indexes
test
users
 
collection重命名
方法1:
 
> show collections;
fucker
mycoll
mycoll_1
system.indexes
test
users
> db.mycoll.renameCollection("Yourcoll");
{ "ok" : 1 }
> show collections;
Yourcoll
fucker
mycoll_1
system.indexes
test
users
方法2:
 
> show collections;
Yourcoll  www.2cto.com  
fucker
mycoll_1
system.indexes
test
users
> use admin;
switched to db admin
> db.runCommand( { renameCollection: "fucker.Yourcoll", to: "fucker.Hiscoll"} );
{ "ok" : 1 }
> use fucker;
switched to db fucker
> show collections;
Hiscoll
fucker
mycoll_1
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
用户名: 验证码:点击我更换图片
最新评论 更多>>

推荐热点

  • Request.ServerVariables 参数大全
  • 执行全文索引时出现权限不足的解决方法
  • 导入excel文件处理流程节点的解决方案
  • 查看sql修改痕迹(SQL Change Tracking on Table)
  • App数据层设计及云存储使用指南
  • PostgreSQL启动过程中的那些事三:加载GUC参数
  • MongoDB安装为Windows服务方法与注意事项
  • Percolator与分布式事务思考(二)
  • 写给MongoDB开发者的50条建议Tip1
网站首页 - 友情链接 - 网站地图 - TAG标签 - RSS订阅 - 内容搜索
Copyright © 2008-2015 计算机技术学习交流网. 版权所有

豫ICP备11007008号-1