You correctly describe the difference between "Embed" and "Reference",
however your document examples are a little off. In your post, both
documents have the actual value (MyId) in the first document, which
means they are both basically a dbref.
Here's different examples that hopefully illustrate the difference a
little better.
Embed:
> db.first_collection.findOne()
{ '_id' : "4d87b4427d190a11fc000003",
'b': {
'MyId' : 33
}
}
Reference:
>var first = db.first_collection.findOne()
{ '_id' : "4d87b4427d190a11fc000003",
'b': "4d87b4427d190a11fc000002"
}
db.second_collection.find( { "_id" : first.b } )
{ '_id' : "4d87b4427d190a11fc000002",
"MyID" : 44
}
On Mar 21, 1:36 pm, Dilip <rdil
...@gmail.com> wrote:
> 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-Embedv...
> 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?
--
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To post to this group, send email to mongodb-user@googlegroups.com.
To unsubscribe from this group, send email to mongodb-user+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/mongodb-user?hl=en.