2015年2月4日星期三

MongoDB week3 Notes

Always try to use embed data and pre-join the data, since there is no join function provided in mongoDB.
There is no guarantee in mongoDB for the consistence of the data, for example, the foreign key constraints. So pre-join the data to make it intact and consistence. 

One-to-one relationships
  • use true linking(“id”)
  • embed the document 
Things need to considerate
  • frequency of access 
  • size of items, growing
  • atomicity of data
One-to-many relationships
  • the best way is to use true linking ( the people living in a city ), when the “many” is large
  • if the data is few, then we can use embed documents ( the blog schema for comets ), when the “many” is few
Many-to-many relationships
  • the actual relationships are few-to-few, then we could embed an array of ids to link the two documents
  • another way is to use embedded documents, but this may not applicable in some situation, for example, in student-teacher relationship, we may insert a teacher into the system before he has any student
Multikey Indexes: index on a array, which makes embedding an array of links more efficiency to query many-to-many relations in MongoDB

Benefits of embedding
  • Improved read performance, reduce the seek latency since the document is stored sequentially on disk
  • One roundtrip to the DB

Tree representations
  • embed a list of children in the document
  • embed a list of ancestors in the document

Store large documents in MongoDB, larger than 16 MB: GridFS, break the large blobs into pieces to store in MongoDB. GridFS break the documents into two collections, one is called chunk collection and each document in it is 16MB, the other is called files collection, which describe the file put in the chunk collection. The documents in the chunk collection have a files_id associate with the files collection.

ODM: lays between application and driver, tell ODM how to handle the class and hand off objects to ODM,  then it will interact with the driver




 

没有评论:

发表评论