How To Create Database In MongoDB
来源:互联网 发布:奶奶踩死孙女知乎 编辑:程序博客网 时间:2024/06/06 17:43
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.1connecting to: test> show dbsadmin 0.03125GBlocal (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 mkyongdbswitched to db mkyongdb> show dbsadmin 0.03125GBlocal (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 dbsadmin 0.03125GBlocal (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.
转载源地址:http://www.mkyong.com/mongodb/how-to-create-database-or-collection-in-mongodb/
- How To Create Database In MongoDB
- How to Create/Drop Database, Table
- How to create Oracle 11g R2 database manually in ASM?
- How to create function polymorphism in C
- How to Create Procedure in DB2
- How To Create Alternate Background In WPF?
- How to create Function/Procedure in Oracle?
- How to create a user in PostgreSQL
- How to create scheduler in liferay portlet
- How to Create QuickAction Dialog in Android
- How to: Create a Binding in Code
- How to create new module in npm
- How to create custom price in Magento?
- How to Create Mysite in SharePoint 2010
- How to create this array in Ruby?
- How to create folder in github repository?
- How to create a function in SQL
- UDACITY - How to Create <Anything> in Android
- Android获取屏幕分辨率及DisplayMetrics简介
- struts学习笔记
- QSqlDatabase类学习笔记
- 百度HI QQ和MSN 阿里旺旺贸易通MSN在线客服在线聊天代码
- 私人珍藏网址
- How To Create Database In MongoDB
- 初识RMI
- 蓝牙RFCOMM连接
- svn: 目录中的条目从本地编码转换到 UTF8 失败 解决办法
- Js中的window.parent ,window.top,window.self详解
- android USB如何修改VID?
- 非托管C++代码调用C#编写的dll方法
- linux小命令
- 【OpenCV学习】前后背景分离