Javascript 在mongodb中需要三个内部值数组 我在Mongodb中有两张带有nodejs的桌子 日重 sub_运动_id锻炼_id体重高度 111111111111 44444444444 120

Javascript 在mongodb中需要三个内部值数组 我在Mongodb中有两张带有nodejs的桌子 日重 sub_运动_id锻炼_id体重高度 111111111111 44444444444 120 ,javascript,node.js,mongodb,Javascript,Node.js,Mongodb,在mongodb中需要三个内部值数组 我在Mongodb中有两张带有nodejs的桌子 日重 sub_运动_id锻炼_id体重高度 111111111111 44444444444 120 74 111111111111 44444444444 122 74 222222222222 44444444444 110

在mongodb中需要三个内部值数组 我在Mongodb中有两张带有nodejs的桌子 日重 sub_运动_id锻炼_id体重高度 111111111111 44444444444 120 74 111111111111 44444444444 122 74 222222222222 44444444444 110 75 111111111111 55555555555 121 75 222222222222 55555555555 122 75 222222222222 55555555555 124 76 次级练习 sub_练习_id名称 111111111箱 22222222哑铃 我想要这种回应 [ { _id:“444” 侧边详图{ { 子作业id:“111111111”, 姓名:“胸部”, 每日详细信息:[ { 体重:120, 身高:74 }, { 体重:122, 身高:74 } ] }, { 子作业编号:“22222”, 姓名:“胸部”, 每日详细信息:[ { 体重:110, 身高:75 } ] } } }, { _id:“5555555” 详细信息:[ { 子作业id:“111111111”, 姓名:“胸部”, 每日详细信息:[ { 体重:121, 身高:75 } ] }, { 子作业编号:“22222”, 姓名:“胸部”, 每日详细信息:[ { 体重:122, 身高:75 }, { 体重:124, 身高:76 } ] } ] } ]
  • 您需要创建具有唯一条件值的组
  • 使用$addtoset创建另一个组

  • 我们不为你做你的工作。 I have two table in Mongodb with nodejs Daily weight sub_exercise_id workout_id weight height 111111111111 44444444444 120 74 111111111111 44444444444 122 74 222222222222 44444444444 110 75 111111111111 55555555555 121 75 222222222222 55555555555 122 75 222222222222 55555555555 124 76 Sub exercise sub_exercise_id name 111111111111 Chest 222222222222 Dumbbel I want this type of response [ { _id:"44444444444" exerside_detail{ { sub_exercise_id:"111111111111", name: "Chest", daily_detail: [ { weight:120, height:74 }, { weight:122, height:74 } ] }, { sub_exercise_id:"222222222222", name: "Chest", daily_detail: [ { weight:110, height:75 } ] } } }, { _id:"55555555555" exerside_detail:[ { sub_exercise_id:"111111111111", name: "Chest", daily_detail: [ { weight:121, height:75 } ] }, { sub_exercise_id:"222222222222", name: "Chest", daily_detail: [ { weight:122, height:75 }, { weight:124, height:76 } ] } ] } ]
    var group = {
        $group: {
            _id: {
                main_id: '$workout_id',
                sub_exercise_id: '$sub_exercises._id'
            },
            exercise_detail: {
                $push: {
                    id: '$_id',
                    weight: '$weight',
                    reps: '$reps',
                    sets: '$sets',
                    auto_finish: '$auto_finish',
                    created_at: '$created_at',
                    time: '$time'
                }
            }
        }
    };
    
    var group1 = {
        $group: {
            _id: '$_id.main_id',
            exercise_detail: {
                $push: {
                    sub_exercise_name: '$_id.sub_exercise_id',
                    exercise_detail1: '$exercise_detail'
                },
            }
        }
    };