简体   繁体   中英

Which approach is better in terms of performance while querying mongodb?

I have two collections. One is students and the other is books . Students may select up to 100 books. So, I may design students collection as

{
'_id'=>'',
 selections['bookid1', 'bookid2', 'bookid3' ... so on]
}

And another solution would be a selections collections

{
'_id'=>''
'book_id'=>'',
'student_id'=>''
 }

Which design is better in terms of query performance. Is there any other reason to choose one over the other?

Mongo does not support join. When you are modeling your data there is tips in mongo docs. The references in mongo go thought databases but isn't a good approach. The preference is use manual reference. For instance

{
  'isbn': '',
  'title': ''
}

{
'name': '',
'books': [isbn numbers... ]

}

http://docs.mongodb.org/manual/core/data-modeling/

http://docs.mongodb.org/manual/reference/database-references/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM