Mongodb(2)创建数据库,删除数据库,创建集合,删除集合,显示文档内容
显示所有数据库列表:show dbs
> show dbs
local .078GB
runoob .078GB
>
显示当前数据库:db
> db
runoob
>
显示所有集合:show collections --显示当前数据库的所有集合
> show collections
col_1
col_2
runoob
system.indexes
>
创建数据库:use DataBase_Name --创建名字为DataBase_Name的数据库,并切换到创建的数据库,当然也可以直接切换到已经存在的数据库
> use mydb
switched to db mydb
> db
mydb
>show dbs #新创建的不会显示,因为里面没有数据
local 0.078GB
runoob 0.078GB
> db.movie.insert({"name":"tutorials yiibai"}) #向当前数据库插入一个集合movie(如果不存在自动创建),并向集合中插入文档
WriteResult({ "nInserted" : 1 })
> show dbs
local 0.078GB
mydb 0.078GB
runoob 0.078GB
> show collections #显示当前数据库中的集合
movie
system.indexes
> db.movie.find() #展示集合中的内容
{ "_id" : ObjectId("578de9095dadb19a13cd9062"), "name" : "tutorials yiibai" }
>
删除数据库:db.dropDatabase()
> show dbs
local 0.078GB
mydb 0.078GB
runoob 0.078GB
> db
mydb
> db.dropDatabase()
{ "dropped" : "mydb", "ok" : 1 }
> show dbs
local 0.078GB
runoob 0.078GB
>
创建集合:db.createCollection(name, options)
name是集合的名字,options(可选)指定有关内存大小和索引
> show dbs
local 0.078GB
runoob 0.078GB
> db #上步删除之后还会显示
mydb
> use runoob #切换数据库
switched to db runoob
> db
runoob
> show collections #显示当前的集合
col_1
col_2
runoob
system.indexes
> db.createCollection("mycollection") #创建集合
{ "ok" : 1 }
> show collections #显示所有的集合
col_1
col_2
mycollection
runoob
system.indexes
>
创建集合的重要选项: createCollection()
> db.createCollection("mycol", { capped : true, autoIndexID : true, size : 6142800, max : 10000 } )
{ "ok" : 1 }
> show collections
col_1
col_2
mycol
mycollection
runoob
system.indexes
> db.yiibai.insert({"name" : "yiibai"})
WriteResult({ "nInserted" : 1 })
> show collections
col_1
col_2
mycol
mycollection
runoob
system.indexes
yiibai
>
删除集合:db.COLLECTION_NAME.drop()
> show collections
col_1
col_2
mycol
mycollection
runoob
system.indexes
yiibai
> db.mycollection.drop()
true
> db.yiibai.drop() #成功删除已经存在的集合
true
> db.mycol.drop()
true
> show collections
col_1
col_2
runoob
system.indexes
> db.rrrrr.drop() #删除不存在的集合,出错
false
>
用find命令来查看文档内容:db.collection_name.find()
> db
runoob
> db.run
db.runCommand( db.runoob
> db.runoob.find()
{ "_id" : ObjectId("578dc96c5dadb19a13cd905e"), "word" : "你好", "chinese" : "今天天气不错啊!", "english" : "today the weather is well!" }
> show collections
col_1
col_2
runoob
system.indexes
> db.col_2.find()
{ "_id" : ObjectId("578dd2b95dadb19a13cd9061"), "name" : "xiaohua", "age" : "" }
> db.col_1.find()
{ "_id" : ObjectId("578dd2255dadb19a13cd905f"), "name" : "chenugnag" }
{ "_id" : ObjectId("578dd23a5dadb19a13cd9060"), "name" : "xiaoming", "age" : "" }
>
Mongodb(2)创建数据库,删除数据库,创建集合,删除集合,显示文档内容的更多相关文章
- MongoDB中的映射,限制记录和记录拼排序 文档的插入查询更新删除操作
映射 在 MongoDB 中,映射(Projection)指的是只选择文档中的必要数据,而非全部数据.如果文档有 5 个字段,而你只需要显示 3 个,则只需选择 3 个字段即可. find() 方法 ...
- POI加dom4j将数据库的数据按一定格式生成word文档
一:需求:将从数据库查处来的数据,生成word文档,并有固定的格式.(dom4j的jar包+poi的jar包) 二:解决:(1)先建立固定格式的word文档(2007版本以上),另存成为xml文件,作 ...
- 使用 powerdesigner 将数据库表结构逆向工程生成对应的word文档
本机系统win10 + mysql 5.7.17 + powerDesigner 16.5 + mysql-connector-odbc-5.3.9-winx32.msi 1 使用 PowerDesi ...
- 如何删除 Win10此电脑 desktop 视频 图片 文档 下载 音乐等文件夹
更改注册表; 1. WIN+R 输入[regedit] 打开注册表管理器 2. 找到路径[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Curren ...
- RDBMS 数据库补丁集补丁号码高速參考-文档 ID 1577380.1
保存此文,高速查询补丁号 Oracle Database - Enterprise Edition - 版本号 8.1.7.0 和更高版本号 本文档所含信息适用于全部平台 补丁集/PSU 补丁号码 ...
- 第49节:Java集合框架中底层文档的List与Set
Java集合框架中的List与Set // 简书作者:达叔小生 Collection -> Set 无序不重复 -> 无序HashSet,需要排序TreeSet -> List 有序 ...
- Java集合框架中底层文档的List与Set
Java集合框架中的List与Set // 简书作者:达叔小生 Collection -> Set 无序不重复 -> 无序HashSet,需要排序TreeSet -> List 有序 ...
- java把集合数据写入txt文档
List<String> list= bs.findJson(); try { BufferedWriter bw = new BufferedWriter(new FileWriter( ...
- VS2012删除选项卡菜单中的"关闭所有文档"
delete the "close all documents" item of tab menu in vs2012 Tools -> Customize -> Co ...
随机推荐
- 对象属性操作-包含kvc---ios
#import <Foundation/Foundation.h> @class Author; @interface Books : NSObject{ @private NSStrin ...
- Maximum number of WAL files in the pg_xlog directory (2)
Jeff Janes: Hi, As part of our monitoring work for our customers, we stumbled upon an issue with our ...
- Don’t Assume – Per Session Buffers
MySQL has a number of global buffers, i.e. your SGA. There are also a number of per session/thread b ...
- 023. Asp.net参数化查询预防Sql注入攻击
/// <summary> /// 参数化查询预防SQL注入式攻击 /// </summary> public int checkLogin(string loginName, ...
- MongoDB管理与开发精要 书摘
摘自:<MongoDB管理与开发精要> 性能优化 创建索引 限定返回结果条数 只查询使用到的字段,而不查询所有字段 采用capped collection 采用Server ...
- OpenJudge计算概论-第二个重复出现的数
/*======================================================================== 第二个重复出现的数 总时间限制: 1000ms 内 ...
- Oboe 提升web 用户体验以及性能
Oboe 地址:http://oboejs.com/ 1.安装 bower bower install oboe 2.使用,ajax 模式 oboe('/myapp/things.json') ...
- 【转】WMI使用的WIN32_类库名
ShadowBy--Win32_ShadowContext--Win32_ShadowCopy--Win32_ShadowDiffVolumeSupport--Win32_ShadowFor--Win ...
- 【转】windows7的桌面右键菜单的“新建”子菜单,在注册表哪个位置,如何在“新建"里面添加一个新项
点击桌面,就会弹出菜单,然后在“新建”中就又弹出可以新建的子菜单栏.office与txt 的新建都是在这里面的.我想做的事情是:在右键菜单的“新建” 中添加一个“TQ文本”的新建项,然后点击它之后,桌 ...
- 功能更强大的格式化工具类 FormatUtils.java
package com.util; import java.text.DecimalFormat; import java.text.ParseException; import java.text. ...