Infinite


  • Home

  • Categories

  • Archives

  • Tags

  • Sitemap

  • RSS

  • Search

MongoDB M201 - Building Indexes

Posted on 2018-03-01 | Post modified 2019-11-16 | In database | Visitors

Building Indexes

两种方式:

  • forground indexes: 建立时候会 block user input,导致这段时间 DB 不可用。这在产品中不可接受。
  • background indexes: 后台建立 index,不会 block operation,代价是build 的时间更长。
    Read more »

MongoDB in Python

Posted on 2018-03-01 | Post modified 2019-11-16 | In database | Visitors

导入数据

导入一个 collection

https://s3.amazonaws.com/edu-static.mongodb.com/lessons/coursera/building-an-app/getting-data-into-mongodb/movies_initial.csv

after create MongoDB Altas cluster, import movies_initial.csv file to the cluster.

1
mongoimport --type csv --headerline --db mflix --c movies_initial --host "mflix-shard-00-00-1cvum.mongodb.net:27017,mflix-shard-00-01-1cvum.mongodb.net:27017,mflix-shard-00-02-1cvum.mongodb.net:27017"--authenticationDatabase admin --ssl --username hansonzhao007 --password Zxsh3017568 --file movies_initial.csv
Read more »

MongoDB M201 - Sorting with indexes

Posted on 2018-02-15 | Post modified 2019-11-16 | In database | Visitors

任何一次 query 的结果都可以被排序,如下:

1
exp.find({first_name:"James"}).sort({first_name:1})

有两种排序方式:
1. 从 disk 里面读取 documents,然后做 in memory 排序。
2. 根据 field 生成 index,index 是排序的。

当我们对没有建立 index 的 field query 后(以上面的first_name 查找排序为例)进行排序。mongoDB 会首先从 collection 里面遍历,完成 query 操作,这会 touch 到所有的 documents。然后 filter 以后的结果,在 memory 中进行排序。如果 query 得到 documents 很多,那么该过程会很费时(mongoDB 会避免超过 32MB 的 in memory 排序)。

Read more »

MongoDB M201 - Single Field Indexes

Posted on 2018-02-15 | Post modified 2019-11-16 | In database | Visitors

导入数据

首先到 https://s3.amazonaws.com/m312/people.json 下载数据。然后导入本地 MongoDB 数据库里。

1
mongoimport -d m201 -c people --drop people.json

MongoDB 启动以后(即 mongod 运行),使用 MongoDB compass 链接本地数据库,查看:

Read more »

MongoDB M201 - How Data is stored on disk

Posted on 2018-02-15 | Post modified 2019-11-16 | In database | Visitors

配置本地环境

默认情况下,MongoDB 数据库目录的组织结构如下:

  • collection-*.wt: 数据库的 collection 文件
  • index-*.wt: 数据库建立的 index 文件

Read more »

lock

Posted on 2018-02-09 | Post modified 2019-11-16 | In program | Visitors

What a lock do?

Lock is used to make sure code in critical section been executed atomically.

Atomic: An operation (or set of operations) is atomic, linearizable, indivisible or uninterruptible if it appears to the rest of the system to occur at once without being interrupted. Atomicity is a guarantee of isolation from interrupts, signals, concurrent processes and threads.

build a Lock

with the help of hardware and os, some primitive instructions can help to build a lock.

Read more »
<1…456…10>
XS Zhao

XS Zhao

60 posts
12 categories
36 tags
GitHub Facebook Instagram E-Mail
Recent Posts
  1. Ethereum Project Infrastructure
  2. Dapp: Lottery Contract
  3. Write ethereum test code
  4. Review: bLSM:* A General Purpose Log Structured Merge Tree
  5. Review: ElasticBF: Fine-grained and Elastic Bloom Filter Towards Efficient Read for LSM-tree-based KV Stores
© 2017 - 2020 XS Zhao
Powered by Hexo
Theme - NexT.Muse
0%