4: Embed dependent fields

原文如下:

 

When considering whether to embed or reference a document, ask yourself if you’ll be

querying for the information in this field by itself, or only in the framework of the larger

document. For example, you might want to query on a tag, but only to link back to the

posts with that tag, not for the tag on its own. Similarly with comments, you might

have a list of recent comments, but people are interested in going to the post that

inspired the comment (unless comments are first-class citizens in your application).

 

If you have been using a relational database and are migrating an existing schema to

MongoDB, join tables are excellent candidates for embedding. Tables that are basically

a key and a value—such as tags, permissions, or addresses—almost always work better

embedded in MongoDB.

 

Finally, if only one document cares about certain information, embed the information

in that document

 

按照上面的例子就是,一个tag表里需要有post的id

你可能感兴趣的:(mongodb)