• Home
  • Jobs
  • Courses
  • Teachers
  • For business
  • Blog
  • ES/EN

0

22
Views
In MongoDB, what is the purpose of embedded documents if the same thing can be achieved without using them?

For example

Instead of a field named, COLUMN_1, that holds an embedded document with fields A, B, and C.

Why not 3 separate fields with names COLUMN_1_A, COLUMN_1_B, COLUMN_1_C.

7 days ago ·

Santiago Trujillo

1 answers
Answer question

0

In mongoDB you prefer to work with documents the way they exist naturaly , afcourse you can create routines that can translate every time and assemble/disasemble the document:

  COLUMN_1:{A:X,B:Y,C:Z}

to:

 COLUMN_1_A:X,COLUMN_1_B:Y,COLUMN_1_C:Z

But this is additonal work that you dont want to do every time , you are a lazy effective developer that prefer just store your json document the way it will be used unless there is a specific use case that make sence to do it this way ... :)

Also please, note embedding is possible up to 100 levels , but max document size is still limited to 16MB , so in your document model it is not expected that you embed all your database in single document...

When you need performance , you add indices and optimize queries , that way your most searched data stay in memory , there is no big difference if your fields are embeded or in the root if they are not indexed ...

7 days ago · Santiago Trujillo Report
Answer question
Remote jobs
Loading

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post job Plans Our process Startups
Legal
Terms and conditions Privacy policy
© 2022 PeakU Inc. All Rights Reserved.