3. NoSQL
• Not Only SQL
• Document-Oriented
• Not a replacement for SQL database
• Schema-less
• Full Text Search, Data-processing, read
faster, write faster
• etc
5. Step Zero
$ mongo!
MongoDB shell version: 2.4.2!
...!
> !
> db!
test!
> show dbs!
local! 0.078125GB!
vcard! 0.203125GB!
> use vcard!
switched to db vcard!
>
Cards
mongo
db
showdbs
use
6. 認識 Collections
> use vcard!
switched to db vcard!
> show collections!
messages!
system.indexes!
users!
> exit!
bye
Cards
show collections
exit
7. 什麼是 Collections
• Document Store (aka folder)
• In JSON and BSON format
• aka XML、MS Word、MS Excel
• Grouping documents
• collections
• Directory hierarchies
• Collections could be considered analogous to
tables
8. Key-Value Paris
• Key–Value stores use the associative
array
• The fundamental data model of
document store
• In-memory document store
• Memory Cache
• Redis and etc.
9. Create a new Database
$ mongo!
!
> show dbs!
local! 0.078125GB!
messages! 0.203125GB!
test! 0.203125GB!
> use mytest!
switched to db mytest!
> db.dropDatabase()!
{ "dropped" : "mytest", "ok" : 1 } Cards
use <new-db-name>
10. Save a new Document
> use mytest!
switched to db mytest!
> db.mytest.save({name: 'jollen'})!
> db.mytest.find()!
{ "_id" : ObjectId("53bf7682af97b69f131d970a"), "name" :
"jollen" }!
>
Cards
save()
find()
⾃自動產⽣生
11. 認識 Schema
• NoSQL 資料庫不需要事先定義欄位
• Table Definition
• Document 的欄位定義稱為 Schema
• Has Schema 或 No Schema
28. Schema 設計原則
• When designing data models, always consider
the application usage of the data (i.e. queries,
updates, and processing of the data) as well as
the inherent structure of the data itself.
• There are two tools that allow applications to
represent these relationships: references and
embedded documents.
• References
• Embedded Data
http://docs.mongodb.org/manual/core/data-modeling-introduction/
33. 關於 Reference Model
• 建議使⽤用的 Data Model
• Using references between documents
• Avoid duplication of data
• Provide sufficient read performance advantage
34. Schema Design
User Collection
_id
name
email
address
age Message Collection
_id
message
uid
35. 專案描述
• 將 Microsoft Excel 資料庫,轉換⾄至 NoSQL
的開發任務
• 客⼾戶資料是以 Excel 維護,現在想將客⼾戶資
料「上雲端」,並製作 App 以隨時追蹤或查
詢
• 將客⼾戶資料轉換為 NoSQL 資料庫。以便進
⾏行 RESTful Web Service 的開發,以及 App
的製作