I have two mongodb collections ‘topics’ and ‘subjects’ with schema :
`topic :
{ _id: ObjectId,
name: String,
subject: ObjectId of subject to which it belongs
}
subject:
{ _id: ObjectId,
name: String
}
`
I have manually defined the foreign key for topic in data-model.
Now, I want to simply count the number of topics for every subject. But I facing this error while grouping my topics by subjects and the error is : “Foreign-keys is not supported by this driver”.
3 Likes
Hi,
Any news about this? I’m getting the same error
“foreign-keys is not supported by this driver”
maz
June 19, 2017, 10:34pm
3
Unfortunately, foreign key relationships aren't supported by our MongoDB driver:
opened 09:44PM - 15 Dec 15 UTC
Database/Mongo
Administration/Metadata & Sync
Type:New Feature
@I'm having trouble creating questions in Metabase using my MongoDB database bec… ause of the way we model relationships, even after adding metadata to map out foreign key relationships. Please help me understand if the various ways that documents can be linked, embedded, or denormalized in MongoDB are supported by Metabase, and if not, consider adding support.
When using MongoDB, various strategies are used for modelling one-to-N relationships. Metabase works OK if the relationship is simply one-to-many modelled as a an ObjectId property on the child model, such as Order -> Product from the Metabase example database. In a Mongoose schema for MongoDB, this might look something like this:
```
var OrderSchema = new mongoose.Schema({
product: {
type: mongoose.Schema.Types.ObjectId,
ref: 'Product'
}
}
```
If we want to model a many-to-many relationship (such as changing order to support multiple products), and try to create an array of ids, Metabase seems to fail to allow queries.
```
var OrderSchema = new mongoose.Schema({
products: [{
type: mongoose.Schema.Types.ObjectId,
ref: 'Product'
}]
}
```
Similarly, if we try to denormalize some part of Product into the Order schema, Metabase also fails.
```
var OrderSchema = new mongoose.Schema({
product: {
_id: {
type: mongoose.Schema.Types.ObjectId,
ref: 'Product'
},
category: String
}
}
```
For reference, different ways of modeling relationships in MongoDB are described here:
http://blog.mongodb.org/post/87200945828/6-rules-of-thumb-for-mongodb-schema-design-part-1
:arrow_down: Please click the :+1: reaction instead of leaving a `+1` or `update?` comment
Is this still an issue. I am getting “mongo driver does not support foreign key” error and cannot filter my questions by name
@ChristineChetty Yes, the issue is still open. Upvote by clicking on the first post of the issue.
Oh no… Have you found a work around that you can recommend? I really just need to filter by a Company ID which is Foreign Key
@ChristineChetty I have no idea how MongoDB works, so I don’t know if you can create views similar to other SQL-based databases, but that would be the workaround.
This seems to indicate that joins are possible: https://github.com/metabase/metabase/issues/9095
I suppose one could join tables to create a view inside metabase and then filter that view
@ChristineChetty When you see an open issue, then it’s still not implemented/fixed, so no, MongoDB doesn’t support joins in Metabase yet.
qatest
March 27, 2024, 7:33am
11
Hey, its working now or not?