I am not sure if I am understanding the distinction made between
embedding an object and holding a reference to it on this page:
http://www.mongodb.org/display/DOCS/Schema+Design#SchemaDesign-Embedvs.Reference
Is it saying that given:
pubic class Foo
{
public Bar b;
}
If Foo and Bar belong to different collections, then Foo is holding a
"reference" to Bar while if they belong to the same collection then
Foo "embeds" Bar?
What is the point of this distinction in practical terms?
If Foo and Bar belong to the same collection, the JSON for a couple of
stored Foo document looks like this:
{
"_id": {
"$oid": "4d87b3417d190a147c000001"
},
"b": {
"MyId": 33
}
}
{
"_id": {
"$oid": "4d87b3417d190a147c000002"
},
"b": {
"MyId": 44
}
}
If they belong to a different collection (so Bar gets an ID of its own
by virtue of being a top-level object of a different collection), the
stored JSON for a Foo document now looks like this:
{
"_id": {
"$oid": "4d87b4427d190a11fc000003"
},
"b": {
"_id": {
"$oid": "4d87b4427d190a11fc000001"
},
"MyId": 33
}
}
{
"_id": {
"$oid": "4d87b4427d190a11fc000004"
},
"b": {
"_id": {
"$oid": "4d87b4427d190a11fc000002"
},
"MyId": 44
}
}
What is the pertinent difference here?