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

本文共 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

你可能感兴趣的文章
这么说吧,NIO很简单,其实就是个牛逼IO
查看>>
七、【应用的主要框架】
查看>>
使用Python快速获取公众号文章定制电子书(二)
查看>>
iOS下JS与OC互相调用(七)--Cordova 基础
查看>>
Three.js 关于立方体贴图产生边缘锯齿问题
查看>>
Nacos v0.7.0:对接CMDB,实现基于标签的服务发现能力
查看>>
【开发问题记录①】关于滑动CollectionView时ContentSize变化的问题
查看>>
java中GC的基本概念
查看>>
building xxx gradle project info的解决办法
查看>>
【Leetcode】98. 验证二叉搜索树
查看>>
Vagrant (一) - 基本知识
查看>>
在 CentOS 7 上搭建 Jenkins + Maven + Git 持续集成环境
查看>>
数据结构与算法 | Leetcode 19. Remove Nth Node From End of List
查看>>
一起来读you don't know javascript(一)
查看>>
[LeetCode] 862. Shortest Subarray with Sum at Least K
查看>>
【分享】终端命令工具 自动生成vue组件文件以及修改router.js
查看>>
[LeetCode] Student Attendance Record I
查看>>
PHP回顾之多进程编程
查看>>
spring boot + redis
查看>>
Ajax技术细节
查看>>