fetch data inside map/reduce

256 views
Skip to first unread message

Martinus Martinus

unread,
Apr 29, 2012, 10:32:52 PM4/29/12
to mongod...@googlegroups.com
Hi,

Can I fetch data using DBRef inside map/reduce function?

Thanks.

Scott Hernandez

unread,
Apr 29, 2012, 11:05:50 PM4/29/12
to mongod...@googlegroups.com
No, not really.

Here is a better explanation and there are more if you go search
through the group/archives:
https://groups.google.com/group/mongodb-user/browse_thread/thread/b462b3e7b9a712b1
> --
> You received this message because you are subscribed to the Google Groups
> "mongodb-user" group.
> To post to this group, send email to mongod...@googlegroups.com.
> To unsubscribe from this group, send email to
> mongodb-user...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/mongodb-user?hl=en.

Martinus Martinus

unread,
Apr 29, 2012, 11:25:33 PM4/29/12
to mongod...@googlegroups.com
Hi Scott,

Thanks for your explanation. During the map phase I need to get documents from another collection which refer by the DBRef on my current collection where I do the map/reduce. Is there any other way to get this documents from another collection inside map/reduce function?

Thanks.

Scott Hernandez

unread,
Apr 29, 2012, 11:46:10 PM4/29/12
to mongod...@googlegroups.com
Are you just trying to group by those references? If so, can you look
them up when you query the results from the client?

In short, there are no joins at the server.

On Sun, Apr 29, 2012 at 8:25 PM, Martinus Martinus

Martinus Martinus

unread,
Apr 30, 2012, 12:29:03 AM4/30/12
to mongod...@googlegroups.com
Hi Scott,

For example I have this collection name animal :

{
     "_id" : 1,
     "type" : "dog",
     "animal_ref" : {
                "$ref" : "name",
                "$id" : ObjectId("4f9615bc0cf2f1a8f17cbb2a")
        }
}

and then I have another "name" collection :
{
     "_id" : 100,
     "food" : "dog_food",
     "quantity" : 10
}

So I do the map/reduce on animal collection, but I need the data from the name collection document (quantity and food) for each type of animal inside the animal collection.

Thanks.

Sam Millman

unread,
Apr 30, 2012, 3:24:11 AM4/30/12
to mongod...@googlegroups.com
Is there any reason why you cant adjust your schema to match your MR?

So put a subdocument called "food" in the animal collection and place the "name" collection inside it.

Martinus Martinus

unread,
Apr 30, 2012, 3:27:43 AM4/30/12
to mongod...@googlegroups.com
Hi Sam,

Because the original "name" collection is not this small, it has many fields inside it. So that's why we put it into another collection.

Thanks.
Reply all
Reply to author
Forward
0 new messages