博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Mongo Collections
阅读量:7052 次
发布时间:2019-06-28

本文共 1500 字,大约阅读时间需要 5 分钟。

hot3.png

MongoDB中的collections就是一系列 BSON documents的集合,相当于关系数据库中的表。

collection将会在第一次往里面插入documents时创建

  1. > show dbs;

  2. admin    (empty)

  3. foo    0.0625GB

  4. fucker    0.0625GB

  5. local    (empty)

  6. test    0.0625GB

  7. > use fucker;

  8. switched to db fucker

  9. > show collections;

  10. fucker

  11. system.indexes

  12. users

  13. > db.test.insert({

    "id" : 1 });

  14. > show collections;

  15. fucker

  16. system.indexes

  17. test

  18. users

collection应该以字母或下划线开头,当然数字也是被允许包含在collection名字内的($为保留字符,不可用于命名)。

collection名最大长度为128个字符,建议不要超80/90个字符

可以使用如下命令来创建collection(一般用于创建Capped collections)

  1. > show collections;

  2. fucker

  3. system.indexes

  4. test

  5. users

  6. > //mongo shell

  7. > db.createCollection("mycoll",{capped:true, size:100000}) //size is in bytes

  8. {

    "ok" : 1 }

  9. > show collections;

  10. fucker

  11. mycoll

  12. system.indexes

  13. test

  14. users

或者使用如下方法
  1. > show collections;

  2. fucker

  3. mycoll

  4. system.indexes

  5. test

  6. users

  7. > db.runCommand( {create:"mycoll_1", capped:true, size:100000} )

  8. {

    "ok" : 1 }

  9. > show collections;

  10. fucker

  11. mycoll

  12. mycoll_1

  13. system.indexes

  14. test

  15. users

collection重命名
方法1:
  1. > show collections;

  2. fucker

  3. mycoll

  4. mycoll_1

  5. system.indexes

  6. test

  7. users

  8. > db.mycoll.renameCollection("Yourcoll");

  9. {

    "ok" : 1 }

  10. > show collections;

  11. Yourcoll

  12. fucker

  13. mycoll_1

  14. system.indexes

  15. test

  16. users

方法2:
  1. > show collections;

  2. Yourcoll

  3. fucker

  4. mycoll_1

  5. system.indexes

  6. test

  7. users

  8. > use admin;

  9. switched to db admin

  10. > db.runCommand( {

    renameCollection: "fucker.Yourcoll", to: "fucker.Hiscoll"} );

  11. {

    "ok" : 1 }

  12. > use fucker;

  13. switched to db fucker

  14. > show collections;

  15. Hiscoll

  16. fucker

  17. mycoll_1

  18. system.indexes

  19. test

  20. users

转载于:https://my.oschina.net/anxuyong/blog/359190

你可能感兴趣的文章
Swift设置自动行高
查看>>
171. Excel Sheet Column Number
查看>>
简单深搜
查看>>
loadView viewDidLoad viewWillAppear viewWillAppear
查看>>
java-http请求
查看>>
WMI VS. ExplorerOM
查看>>
问题的定义和管理复杂度《Code Complete 2》
查看>>
Android init.rc解析【转】
查看>>
算法(Algorithms)第4版 练习 2.2.11(2)
查看>>
云解放了计算机这台机器,让计算的能力彻底从一个箱子里释放出来,回归了计算的本质。...
查看>>
Java ---- baidu评价抽取关键词-商品评论
查看>>
LR事务、集合点
查看>>
html 笔记
查看>>
2018.12.23 区块链论文翻译
查看>>
用Spring MVC开发简单的Web应用程序
查看>>
hession
查看>>
[CF813E]Army Creation
查看>>
[洛谷P3384]【模板】树链剖分
查看>>
ABP源码分析八:Logger集成
查看>>
oracle:对象(object)操作
查看>>