我有一个关于权限列表管理的需求,数据库固定使用 MongoDB,前端接收的数据格式如下:
interface Access {
id: string;
parentId?: string;
name: string;
code: string;
children?: Array<Access>
}[];
这种数据结构我应该以什么方式来存储到MongoDB中最好❓以及如何操作数据呢❓
大致需求如下:
1. 查询权限:返回所有的数据,格式为 Array<Access>
2. 添加权限:前端传过来的参数是 {parentId, name, code},然后我找到parentId 的记录,在 children 里面添加数据即可。
3. 编辑权限:前端传过来的参数是 {id, name, code},然后我找到id的记录,修改name和code。
4. 删除权限:前端传过来的参数是 {id},然后我找到id的记录,删除该条以及该条嵌套的children记录。
辛苦各位大佬帮忙解决,感激不尽。
interface Access {
id: string;
parentId?: string;
name: string;
code: string;
children?: Array<Access>
}[];
这种数据结构我应该以什么方式来存储到MongoDB中最好❓以及如何操作数据呢❓
大致需求如下:
1. 查询权限:返回所有的数据,格式为 Array<Access>
2. 添加权限:前端传过来的参数是 {parentId, name, code},然后我找到parentId 的记录,在 children 里面添加数据即可。
3. 编辑权限:前端传过来的参数是 {id, name, code},然后我找到id的记录,修改name和code。
4. 删除权限:前端传过来的参数是 {id},然后我找到id的记录,删除该条以及该条嵌套的children记录。
辛苦各位大佬帮忙解决,感激不尽。