Mongodb recommended deposit list field or multiple records?

Application scenario: the background management system assigns visible menu permissions to the created users. For example, if user An is assigned 10 menus, then the user can see the 10 menus in the menu bar after logging in. Now the menu is up to 3 levels. According to the current business, the maximum number of menus assigned by a single user is no more than 30.

now the database uses MongoDB, to store menu permissions in two ways:

  1. menu list, that is, a menu list is stored in each user permissions table, so that all menus under that user can be seen in a single query record.
  2. menu items are tiled, with each row of records corresponding to a user"s menu, so that if the user sees 20 menus, there will be 20 rows of records in the table.
The advantage of

scheme 1 is that it is convenient to store, and all menu lists can be returned by a single record when querying; the advantage of scheme 2 is that it is convenient to find out which users are given a menu to see.

individuals prefer option 2, but are not sure whether it is a common design approach. Do you have any suggestions? Thank you!


under sql, scheme 2 is better. Under mongo, scenario 1 is better.
I don't know if there is a concept of user permission group in your project.
if there is a permission group, it is an array of menu items in the collection of a permission group.
if there is no permission group, you can follow the plan 1, in each user table, or in a separate user permission table. Save an array of menus.
of course, it may be more appropriate to save the id array of menu items.

the array in mongo can also be indexed, and the query is very convenient.
in addition, you can also refer to mongo's own permission system, whose permission settings are also saved in the mongo database, usually the users table under the admin library. If your mongo has rights management enabled, and the name of the permission library is admin, you can check it with the following command:

  mongo official document-Array Index  

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e461c4-43b03.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e461c4-43b03.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?