时间:2021-07-01 10:21:17 帮助过:24人阅读
下面是mongodb的一些基本概念:
为了易于理解,咱们把MongoDB中的概念与关系数据库对比一下:

一、文档
文档是mongodb的核心概念。多个键值有序的放置在一起便是文档。简单的例子:
1 {"greeting":"Hello World","foo":15}
2 {"foo":15,"greeting":"Hello World"}
3 {"foo":15}
4 {"Foo":15}
5 {"Foo":"15"}
二、集合
集合就是一组文档,如果说文档如关系数据库中的行,那么集合就如同表。集合有如下特点:
1、无模式
集合是无模式的,这意味着集合里可以存储各种各样的文档。那么是不是mongodb中只需要一个集合就可以了呢?答案是否,下面是一些理由:
2、命名
我们可以名字来标识集合,下面是一些约束:
组织集合的一种常用惯例是按命名空间划分子集合,比如开发一个博客
三、数据库
数据库包括多个集合,一个实例中包括多个数据库,一般一个应用对应一个数据库。数据库的命名规则:
关于数据库的相关操作:
#查看当前数据库 > db test #切换当前数据库 > use local switched to db local > db local
获得帮助:
> help
db.help() help on db methods
db.mycoll.help() help on collection methods
sh.help() sharding helpers
rs.help() replica set helpers
help admin administrative help
help connect connecting to a db help
help keys key shortcuts
help misc misc things to know
help mr mapreduce
show dbs show database names
show collections show collections in current database
show users show users in current database
show profile show most recent system.profile entries with time >= 1ms
show logs show the accessible logger names
show log [name] prints out the last segment of log in memory, ‘global‘ is default
use <db_name> set current database
db.foo.find() list objects in collection foo
db.foo.find( { a : 1 } ) list objects in foo where a == 1
it result of the last line evaluated; use to further iterate
DBQuery.shellBatchSize = x set default number of items to display on shell
exit quit the mongo shell
>
【二】MongoDB入门
标签:shel 效率 val 对比 alt size 类型 关系数据库 world