Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do the MongoDB docs recommend not using DBREFs?

The MongoDB docs for DBREFs say:

Unless you have a compelling reason to use DBRefs, use manual references instead.

Why? DBREFs seem more easy to use, since they encode the database and collection names, which would lead to less hard-coding in the application. Plus, DBREF is a standard format that many drivers understand.

This question is related, but not exactly the same:

MongoDB - is DBREF necessary?

The answer to that question is that embedding/denormalization is preferable to linking, but it doesn't answer the question of why manual linking is preferable to DBREFs.

like image 905
Max Heiber Avatar asked Mar 18 '26 23:03

Max Heiber


1 Answers

Here a conclusion of all I viewed.

Using DBRef is not a join operation, it will automatically query the second or more times, depends on how much DBRef you have got in this collection fields.

Assuming you have a collection that its model has 10 DBRef, you make query for 10 elements' list of it and one of these DBRef is really needed. Once you query, Mongodb will runs 101(1 + 10*10) queries, automatically, no matter you need these DBRef or not. If you query these field manually, just a few coding and only 11(1 + 1*10) queries are needed.

So, what do you say?

like image 189
Kroderia Avatar answered Mar 20 '26 17:03

Kroderia



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!