怎么创建MongoDB数据库
MongoDB didn’t provides any command to create “database“. Actually, you don’t need to create it manually, because, MangoDB will create it on the fly, during the first time you save the value into the defined collection (or table in SQL), and database.
For developer from SQL background, we need to create a database, table and insert values into table manually. In MongoDB, you don’t need to mention what you want to create, when first time you save the value into the defined collection (table), under selected database, MangoDB will create the value, collection and database automatically.
MongoDB contains “
db.createCollection()
” to create collection manually, but Not database.In this guide, we will show you how and when MongoDB will create the database and collections.
1. Show all database
Issue “show dbs
” to display all available databases.
MongoDB shell version: 1.8.1
connecting to: test
> show dbs
admin 0.03125GB
local (empty)
Currently, only two databases are available – “admin” and “local“.
2. Define a database name
Issue “use new-databasename
” to switch from default database to define database (even non-exists database name will work). However, MangoDB doesn’t create any database yet, until you save something inside.
> use mkyongdb
switched to db mkyongdb
> show dbs
admin 0.03125GB
local (empty)
P.S Database “mkyongdb” is not created yet.
3. Save It
Define a collection named “users“, and save a dummy document(value) inside.
> db.users.save( {username:"mkyong"} )
> db.users.find()
{ "_id" : ObjectId("4dbac7bfea37068bd0987573"), "username" : "mkyong" }
>
> show dbs
admin 0.03125GB
local (empty)
mkyongdb 0.03125GB
This says, “save this document (value) ‘{username:"mkyong"}
‘ into the ‘user’ collection”. When this “save” operation is performed, MangoDB will create the “user” collection, and “mkyongdb” database automatically.
怎么创建MongoDB数据库的更多相关文章
- 【转载】CentOS6.5_X64下安装配置MongoDB数据库
[转载]CentOS6.5_X64下安装配置MongoDB数据库 2014-05-16 10:07:09| 分类: 默认分类|举报|字号 订阅 下载LOFTER客户端 本文转载自zhm&l ...
- CentOS 6.5_X64下安装MongoDB数据库
1.下载MongoDB 官网下载地址:https://www.mongodb.org/downloads 具体链接:https://fastdl.mongodb.org/linux/mongodb-l ...
- NodeJS连接MongoDB数据库时报错
今天第一次尝试连接MongoDB数据库,具体步骤也很简单. 首先,通过NodeJS运行环境安装MongoDB包,进入要安装的目录,执行语句 npm install mongodb 安装成功后,通过如下 ...
- 安装配置MongoDB数据库
一.关闭SElinux.配置防火墙 1.vi /etc/selinux/config #SELINUX=enforcing #注释掉 #SELINUXTYPE=targeted #注释掉 SELINU ...
- Linux下定时切割Mongodb数据库日志并删除指定天数前的日志记录
此为在网络上找来的,觉得很好! 实现目的: 对Mongodb数据库日志按天保存,并且只保留最近7天的日志记录. 具体操作: 使用Mongodb数据库自带的命令来切割日志 ps -def | grep ...
- 入门系列之在Ubuntu 14.04上备份,还原和迁移MongoDB数据库
欢迎大家前往腾讯云+社区,获取更多腾讯海量技术实践干货哦~ 本文由信姜缘 发表于云+社区专栏 MongoDB是最受欢迎的NoSQL数据库引擎之一.它以可扩展,强大,可靠和易于使用而闻名.在本文中,我们 ...
- Linux下安装配置MongoDB数据库
说明: 操作系统:CentOS 5.X 64位 IP地址:192.168.21.130 实现目的: 安装配置MongoDB数据库 具体操作: 一.关闭SElinux.配置防火墙 1.vi /etc/s ...
- java操作mongodb数据库实现新建数据库,新建集合,新建文档
*首先明确一点,要通过java代码创建mongodb数据库实例,需要同时创建集合和文档. 代码实现: /* 建立与mongodb数据库的连接,可指定参数,如:MongoClient client = ...
- 用shell脚本实现MongoDB数据库自动备份
一.创建MongoDB备份目录 用来存放数据 mkdir -p /data/mongodb_bak/mongodb_bak_now mkdir -p /data/mongodb_bak/mongodb ...
随机推荐
- Spring+MyBatis实践—MyBatis数据库访问
关于spring整合mybatis的工程配置,已经在Spring+MyBatis实践—工程配置中全部详细列出.在此,记录一下几种通过MyBatis访问数据库的方式. 通过sqlSessionTempl ...
- TPS和QPS的区别
一.TPS:Transactions Per Second(每秒传输的事物处理个数),即服务器每秒处理的事务数.TPS包括一条消息入和一条消息出,加上一次用户数据库访问.(业务TPS = CAPS × ...
- UR #13 Yist
第一次打UR,打了一个半小时就弃疗了QAQ 这是我唯一一道考试的时候做出来的题目,其他两道连暴力都懒得写了 很容易发现对于每个要删除的点 我们找到左边第一个比他小的不用删除的点,右边第一个比他小的不用 ...
- OpenStack 部署运维实战
http://www.ibm.com/developerworks/cn/cloud/library/1408_zhangxl_openstack/#icomments 本文为您介绍了网易公司基于 O ...
- 观察者模式实现INotifyPropertyChanged
其实一直不知道INotifyPropertyChanged这个接口中PropertyChanged事件是什么时候有值的,因为在使用的时候,只要按步骤来就可以,因为我自己并没有对这个事件赋值,所以很好奇 ...
- semantic versioning语义化版本号
语义化版本号 是由github创始人 Tom Preston-Werner 发起的一个关于软件版本号的命名规范,关于这个规范详细的说明可以在 官网 查看,也可访问其 GitHub项目页面 ,官网文档: ...
- iOS(Swift) TextField限制输入文本的长度(不是字数)
最近做项目有一个特殊需求,就是需要限制一个TextField的输入文本的长度在一定范围内(注意,不是字数),上网查了一圈没有找到类似文章,这里把我的方法写进来,mark一下: 1.对TextField ...
- 【POJ】3468 A Simple Problem with Integers
这题用线段树轻松解了,重新用树状数组解,关键点是区间更新.公式推导如下:sum[x] = org_sum[x] + delta[1]*x + delta[2]*(x-1) + delta[x]*1 ...
- 【HDOJ】4426 Palindromic Substring
综合性很强的一道题目,结合manacher,后缀数组,哈希,RMQ,二分可解.基本思路是通过manacher可以找到所有可能的回文串,哈希去重,后缀数组二分找数目.最后暴力求解.需要注意kth需要为_ ...
- SpringMVC中对Controller使用AOP
转自http://usherlight.iteye.com/blog/1306111 正确配置spring aop,在controller中使用AOP 在controller中使用AOP的问题主要在于 ...