mongodb概述_MongoDB概述

mongodb概述

MongoDB consists of a set of databases. Each database again consists of Collections. Data in MongoDB is stored in collections. The below figure depicts the typical database structure in MongoDB.

MongoDB由一组数据库组成。 每个数据库又由集合组成。 MongoDB中的数据存储在集合中。 下图描述了MongoDB中的典型数据库结构。

Overview of MongoDB

MongoDB中的数据库 (Database in MongoDB)

Database in MongoDB is nothing but a container for collections. We will learn how to create a new Database, drop a Database and how to use an existing Database in the coming lessons.

MongoDB中的数据库不过是集合的容器。 在接下来的课程中,我们将学习如何创建新数据库,删除数据库以及如何使用现有数据库。

MongoDB中的集合 (Collections in MongoDB)

  • Collection is nothing but a set of MongoDB documents. These documents are equivalent to the row of data in tables in RDBMS. But, collections in MongoDB do not relate to any set schema as compared to RDBMS. Collections are a way of storing related data. Being schemaless, any type of Document can be saved in a collection, although similarity is recommended for index efficiency. Document's can have a maximum size of 4MB.

    集合不过是一组MongoDB文档而已。 这些文档等效于RDBMS中表中的数据行。 但是,与RDBMS相比,MongoDB中的集合与任何集合模式都不相关。 集合是一种存储相关数据的方法。 没有架构,任何类型的文档都可以保存在集合中,尽管建议使用相似性以提高索引效率。 文件的最大大小为4MB。

  • We can use namespace to logically group and nest collections. For example : There can be one collection named db.studytonight.users to save user informations, then there can be others like db.studytonight.forum.questions and db.studytonight.forum.answers to store forum questions and answers respectively.

    我们可以使用命名空间对集合进行逻辑分组和嵌套。 例如:可以有一个名为db.studytonight.users集合来保存用户信息,然后可以有诸如db.studytonight.forum.questionsdb.studytonight.forum.answers类的db.studytonight.forum.answers来分别存储论坛问题和答案。

  • If we create an Index on a namespaced collection, it will only apply on that namespace only. We will learn later in this tutorial, how to create indexes.

    如果我们在命名空间集合上创建索引 ,则该索引将仅适用于该命名空间。 我们将在本教程的后面部分学习如何创建索引。

  • A collection is physically created as soon as the first document is created in it.

    在第一个文档中创建集合后,便会立即创建一个集合。

  • You must be wondering why create multiple collections with different namespace, when we can keep any form or data in a single collection itself. It's because, MongoDB does not index attributes for totally unrelated documents. So it is advised to keep related data in collections.

    您一定想知道为什么在我们可以将任何形式或数据保留在单个集合本身中的情况下,为什么创建具有不同名称空间的多个集合。 这是因为,MongoDB不会为完全不相关的文档建立索引属性。 因此建议将相关数据保留在集合中。

MongoDB中的文档 (Document in MongoDB)

Document in MongoDB is nothing but the set of key-value pairs. These documents will have dynamic schema which means that the documents in the same collection do not need to possess the same set of fields.

MongoDB中的文档不过是一组键值对。 这些文档将具有动态模式,这意味着同一集合中的文档不需要拥有相同的字段集。

Since MongoDB is considered as a schema-less database, each collection can hold different type of objects. Every object in a collection is known as Document, which is represented in a JSON like (JavaScript Object Notation) structure(nothing but a list of key-value pair). Data is stored and queried in BSON, its binary representation of JSON-like data. You can know more about BSON format from this webpage → BSON Specification and BSON Types

由于MongoDB被视为无模式数据库,因此每个集合可以容纳不同类型的对象。 集合中的每个对象都称为Document,它以JSON形式表示,例如(JavaScript Object Notation)结构(仅键值对列表)。 数据在BSON中存储和查询, BSON是类似JSON数据的二进制表示形式。 您可以从此页面了解有关BSON格式的更多信息→ BSON规范BSON类型

MongoDB中的样本数据 (Sample Data in MongoDB)

Sample Data in MongoDB

Note: In the above figure, the field _id represents the primary key identifier of the given document. MongoDB also stores the values in the form of arrays of value as well. Infact any type of data can be stored as values, and nothing requires to be pre-defined. In other words, you do not have to predefine the type of data to be stored, you can store anything you want. Remember, MongoDB is schema-less.

注意:在上图中,字段_id代表给定文档的主键标识符。 MongoDB还以值数组的形式存储值。 实际上,任何类型的数据都可以存储为值,并且不需要预先定义任何内容。 换句话说,您不必预先定义要存储的数据类型,就可以存储所需的任何数据。 记住,MongoDB是无架构的。

Documents are not identified by a simple ID, but by an object identifier type. The default Id is a combination of machine identifier, timestamp and process id to keep it unique, but user can changes it to anything.

文档不是通过简单的ID来标识的,而是通过对象标识符的类型来标识的。 默认ID是机器标识符,时间戳和进程ID的组合,以使其保持唯一,但用户可以将其更改为任何值。

数组作为值的示例 (Example of Array as value)

{ _id : 112233,
  name : "Viraj",
  education : [
           {
              year : 2029,
              course : "BTECH",
              college : "IIT, Delhi"
            },
           {
              year : 2031,
              course : "MS",
              college : "Harvard College"
           }
  ]
}

一个文档中不同数据类型的示例 (Example of Different Datatypes in one Document)

The value of fields in a document can be anything, including other documents, arrays, and arrays of documents, date object, a String etc.

文档中字段的值可以是任何值,包括其他文档,数组和文档数组,日期对象,字符串等。

var mydoc = {
    _id : ObjectId("5099803df3f4948bd2f98391"),
    name : { first: "Alan", last: "Turing" },
    birth : new Date('Jun 23, 1912'),
    death : new Date('Jun 07, 1954'),
    contribs : [ "Turing machine", "Turing test", "Turingery" ],
    view : NumberLong(1250000)
}

翻译自: https://www.studytonight.com/mongodb/overview-of-mongodb

mongodb概述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值