MongoDB database schema design advice (sharing) -
I am trying to create a media-oriented API with nodes .JS and MongoDB. The main part of the app is the media unit. You can share the media unit with users, events, etc. The schema is as follows:
created: '12 January 2014 ', Title:' New Book ', Description:' This is a [drama, 'new'], Event: [123] ',' 234 '], Users: [' 123 ',' 234 '],' New Book ', File Type: 1, Size: 230, Categories: [' Horror ',' Romantic '], Tags: [' 111 ',' 222 '], Type: 1, Producer:' John Gallagher ', Yuri:' http://test.com/book.pdf '
Operations:
- Media A is shared with user B, C
- I'm trying to get the media to get an event D, E < / Li>
Added in the query:
-
Show all the media which is shared with user B
Db.media.find ({ User: '111'})
-
Show all media within the eventD
db.media.find ({Event: '234'})
I am not sure how to approach this problem. Is this an appropriate approach to a given goal?
As commented on, there is nothing wrong with this type of schema that you do The more you want, the more you are, the more you have explained yourself at this point. It has also been mentioned that here only your actual obligation how many things you want to put in these arrays, and this document has an effect on size. There is also a point where too many items in a array will bring some performance down to a considerable fall.
But if your size of your documents is going to be relatively small, then it should be all right.
Something unknowingly something got points:
Since you have a structure with many array elements, you can find yourself To filter the results on a combination of two or more elements, then in this case, the section on the Multicay index is worth reading, and understanding the impact on various questions and how you can make your indexes Are there. In essence, only one Multikey per compound index field, as the limit of permutations on involving more than one.
Whether your embedded arrays look like moving beyond proper numbers can be worth a look at the documentation on the use case for elements. It involves some cases, and there is a section in the number of large organizations, which discusses the technique known as "bilting" which can be used for you.
Comments
Post a Comment