文档介绍:Data Store with MongoDB
Roger Xia
What is document-oriented?
JSON objects
Not relational
Not OODB
Database schema != program “schema”
Terms
Row -> JSON document
Tables -> collections
Indexes -> index
Join -> embedding and linking
Choose a schema that
makes queries easy
makes queries fast
facilitates atomicity
facilitates sharding
Key question: embed vs. link
“Contains relationship”: embed
Embed = “pre-joined”
Links: client/server turnarounds
On a close call, embed. Use rich documents.
Note the 4MB object size limit
Arbitrary limit but pushes one towards good designs
Database References
Simple Direct/Manual Linking (manually coded link)
DBRef (creating references between documents)
Querying
Query Expression Objects
query objects and Advanced Queries
Related driver docs: Python, Java, Ruby, PHP
Query Options
Field Selection (request only certain fields be returned)
Sorting
Skip and Limit (for easy paging, skip the first 20 last names, and limit our result set to 10)
slaveOk (Querying Secondaries)
Cursors (Cursors are then used to iteratively retrieve all the documents returned by the query.)
Related driver docs: Python, Java, Ruby, PHP