Aggregation framework with DBRef

1,553 views
Skip to first unread message

Ratish Puduppully

unread,
Sep 9, 2012, 10:31:15 PM9/9/12
to mongod...@googlegroups.com
Hi,

We have two collections:Event and Alerts

Each record in Alert refer to a record in Events collection. We use DBRef for the same

I want to aggregate records in Alert collection. I was going through the Aggregation framework
Came across the below issue:

Warning

 

The pipeline cannot operate on values of the following types: BinarySymbolMinKeyMaxKeyDBRefCode, andCodeWScope.


I want to understand if it is feasible to support DBRef for MongoDB aggregation framework in future.

Thanks,
Ratish

Stephen Steneker

unread,
Sep 10, 2012, 12:52:21 AM9/10/12
to mongod...@googlegroups.com
I want to understand if it is feasible to support DBRef for MongoDB aggregation framework in future.

Hi Ratish,

DBRefs are a convention used by applications, but do not have any special support in the MongoDB server.

MongoDB explicitly does not support joins, so it is unlikely that DBRef support will be added to the aggregation framework.  A DBRef would require read access to other collections during Aggregation or Map/Reduce, which could potentially lead to performance issues and deadlocks.

A more typical approach would be to structure your data model so joins are not required (i.e. embed Alerts in Events, or vice-versa).

A possible (but rather roundabout) workaround might be to use successive map/reduce with the 'merge' output option similar to:
 http://tebros.com/2011/07/using-mongodb-mapreduce-to-join-2-collections/

Cheers,
Stephen

Rubén Bressler Camps

unread,
Jul 4, 2014, 5:48:31 PM7/4/14
to mongod...@googlegroups.com
How obtain only $id attribute from DBRef in an aggregation result?

Stephen Steneker

unread,
Jul 4, 2014, 7:12:06 PM7/4/14
to mongod...@googlegroups.com
On Saturday, 5 July 2014 07:48:31 UTC+10, Rubén Bressler Camps wrote:
How obtain only $id attribute from DBRef in an aggregation result?

Hi Rubén,

As at MongoDB 2.6, the aggregation pipeline does not have support for projecting attributes of DBRef fields:

I've added a feature suggestion for this that you can watch/upvote: https://jira.mongodb.org/browse/SERVER-14466.

Unfortunately there isn't any good server-side workaround in the interim. You could extract the DBRef $id values from the results in your application code, but if you want to manipulate these values in your aggregation pipeline you would have to first copy the values to a supported field type (string or ObjectId).

Regards,
Stephen

Reply all
Reply to author
Forward
0 new messages