博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
MongoDB权威指南学习笔记
阅读量:6073 次
发布时间:2019-06-20

本文共 4140 字,大约阅读时间需要 13 分钟。

Chapter 1 Introduction

secondary indexes

range queries
sorting
aggregations
geospatial indexes

MongoDB is a document-oriented database, not a relational one.

  • scale out easier
  • represent complex hierarchical relationships with a single record
  • no predefined schemas

scaling a database = scale up(get a bigger machine) OR scale out(partition data across more machines - cheaper and more scalable but hard to administer)

MongoDB was designed to scale out. document-oriented data model makes it easier to split up data across multiple servers.

Features of MongoDB

  • Indexing: support generic secondary indexes, allowing a variety of fast queries, and provides unique, compound, geospatial and full-text indexing
  • Aggregation: support "aggregation pipeline" that allows building complex aggregation
  • Special collection types: MongoDB supports time-to-live collections such as sessions, fixed-size collections useful for holding recent data, such as logs
  • File storage: easy-to-use protocol for storing large files and file metadata

Chapter 2 Getting Started

Documents

  • a document is the basic unit of data for MongoDB and is roughly equivalent to a row in relational DB. document -> row
  • collection -> table with dynamic schema
  • a single instance of MongoDB host multiple independent databases, each of which can have its own collections
  • Every document has a special key, _id unique within a collection
  • MongoDB comes with a JavaScript shell, which is useful for the administration of MongoDB instances and data manipulation

  • MongoDB is type-sensitive and case-sensitive. Ex. {"foo" : 3} {"foo" : "3"} type-sensitive {"foo" : 3} {"Foo" : 3} case-sensitive
  • MongoDB cannot contain duplicate keys. Ex. illegal: {"greeting" : "hello", "greeting" : "hello, mongo"} duplicate keys
  • Key/value pairs in documents are ordered: Ex. {"x" : 1, "y" : 2} {"y" : 2, "x" : 1}

Collections

a collection is a group of documents.

dynamic schemas means that the documents within a single collection can have any number of different "shapes"
{"greeting" : "Hello"} {"foo" : 5}

Subcollections: just a convention for organizing collections is to use namespaced subcollections separated by the . character. Ex. blog.posts blog.authors only for organizational purposes only

Databases

databases -> group collections -> group documents

a single instance of MongoDB can host several databases, each database has its own permissions, and each database is stored in separate files on disk.

good design: store all data for a single application in the same database

several reserved database names:

admin: this is the root database, in terms of authentication.
local: this database will never be replicated and can be used to store any collections that should be local to a single server
config: When MongoDB is being used in a sharded setup, it uses the config database to store information about the shards

Download

Move the folder to $mv mongodb-osx-ssl-x86_64-4.0.5 usr/local/mongodb
create the default data directory $sudo mkdir -p /data/db
give permission to write to the directory before starting MongoDB: sudo chown codebind /data/db

default socket connections on port 27017

User mongod to start the MongoDB server and wait for a connection
mongod also sets up a very basic HTTP server that listens on a port 1000 higher than the main port, open a web browser and go to http://localhost:28017

Running the shell 【用shell来对mongodb 进行操作】

Use mongo to start the shell, the shell automatically attempts to connect to a MongoDB server on startup, make sure start mongodb before starting the shell

The shell is a full-featured JavaScript interpreter, capable of running JavaScript programs, we can use standard JavaScript libraries and call JavaScript functions

A MongoDB Client

db show the current database

use foobar: select another database
db.blog.insert(post): insert function adds a document to a collection
db.blog.find(): see the inserted post
findOne()
db.blog.update()
db.blog.remove(): called with no parameters, it removes all documents from a collcetion. It can also take a document specifying criteria for removal.

Data Types

转载于:https://www.cnblogs.com/kong-xy/p/10152448.html

你可能感兴趣的文章
3.使用maven创建java web项目
查看>>
笔记本搜索不到某一AP广播的SSID,信道的原因
查看>>
基于Spring MVC的异常处理及日志管理
查看>>
MediaBrowserService 音乐播放项目《IT蓝豹》
查看>>
MySQL入门12-数据类型
查看>>
Windows Azure 保留已存在的虚拟网络外网IP(云服务)
查看>>
修改字符集
查看>>
HackTheGame 攻略 - 第四关
查看>>
js删除数组元素
查看>>
带空格文件名的处理(find xargs grep ..etc)
查看>>
华为Access、Hybrid和Trunk的区别和设置
查看>>
centos使用docker下安装mysql并配置、nginx
查看>>
关于HTML5的理解
查看>>
需要学的东西
查看>>
Internet Message Access Protocol --- IMAP协议
查看>>
Linux 获取文件夹下的所有文件
查看>>
对 Sea.js 进行配置(一) seajs.config
查看>>
dom4j解析xml文件
查看>>
第六周
查看>>
解释一下 P/NP/NP-Complete/NP-Hard 等问题
查看>>