// 1
{
“_id”: ObjectId(“62c238b03148c6cc6594dc9b”),
“name”: “首页”,
“icon_name”: “HomeFilled”,
“router_name”: “Home”,
“router_path”: “/home”,
“role_group”: [
“admin”,
“common”
],
“is_operate”: false,
“describe”: “”,
“create_time”: ISODate(“2022-07-04T00:47:44.977Z”),
“children”: [ ],
“__v”: NumberInt(“0”)
}
// 2
{
“_id”: ObjectId(“62c238b03148c6cc6594dc9c”),
“name”: “系统设置”,
“icon_name”: “Setting”,
“router_name”: “System”,
“router_path”: “/system”,
“role_group”: [
“admin”
],
“is_operate”: false,
“describe”: “”,
“children”: [
{
“name”: “角色管理”,
“icon_name”: “Postcard”,
“router_name”: “Role”,
“router_path”: “/system/role”,
“role_group”: [
“admin”
],
“is_operate”: false,
“describe”: “”,
“_id”: ObjectId(“62c238b03148c6cc6594dc9d”),
“create_time”: ISODate(“2022-07-04T00:47:44.979Z”),
“children”: [ ]
},
{
“name”: “菜单管理”,
“icon_name”: “Menu”,
“router_name”: “Menu”,
“router_path”: “/system/menu”,
“role_group”: [
“admin”
],
“is_operate”: false,
“describe”: “”,
“_id”: ObjectId(“62c238b03148c6cc6594dc9e”),
“create_time”: ISODate(“2022-07-04T00:47:44.98Z”),
“children”: [ ]
},
{
“name”: “部门管理”,
“icon_name”: “OfficeBuilding”,
“router_name”: “Dept”,
“router_path”: “/system/dept”,
“role_group”: [
“admin”
],
“is_operate”: false,
“describe”: “”,
“_id”: ObjectId(“62c238b03148c6cc6594dc9f”),
“create_time”: ISODate(“2022-07-04T00:47:44.98Z”),
“children”: [ ]
},
{
“name”: “用户管理”,
“icon_name”: “User”,
“router_name”: “User”,
“router_path”: “/system/user”,
“role_group”: [
“admin”
],
“is_operate”: false,
“describe”: “”,
“_id”: ObjectId(“62c238b03148c6cc6594dca0”),
“create_time”: ISODate(“2022-07-04T00:47:44.98Z”),
“children”: [ ]
}
],
“create_time”: ISODate(“2022-07-04T00:47:44.98Z”),
“__v”: NumberInt(“0”)
}
数据结构如上,比如已知“菜单管理”的ID“62c238b03148c6cc6594dc9e”,如何能查询到它所在对象?还有一个问题就是要能查询到多级,就是现在数据结构是两层,如果三层、四层要如何查询?
第一个问题:
db.world.find({‘children.name’:’菜单管理’})
第二个问题:
hello> db.world.find({‘children.children.name’: ‘角色列表’})
[
{
_id: ObjectId(“62e4b9c7200d24739b5064da”),
name: ‘系统设置’,
icon_name: ‘Setting’,
router_name: ‘System’,
router_path: ‘/system’,
role_group: [ ‘admin’ ],
is_operate: false,
describe: ”,
children: [
{
name: ‘角色管理XXX’,
icon_name: ‘Postcard’,
router_name: ‘Role’,
router_path: ‘/system/role’,
role_group: [ ‘admin’ ],
is_operate: false,
describe: ”,
create_time: ISODate(“2022-07-04T00:47:44.979Z”),
children: [ { name: ‘角色列表’ } ]
}
],
create_time: ISODate(“2022-07-04T00:47:44.980Z”),
__v: 0
}
]