How to do inner joining in MongoDB?

后端 未结 4 840
醉梦人生
醉梦人生 2021-02-08 02:31

Is it possible to do SQL inner joins kind of stuff in MongoDB , well i know there is

$lookup

attribute in aggregation pipeline and

4条回答
  •  Happy的楠姐
    2021-02-08 03:14

    Will this help

    const RolesSchema = new Schema({
      ....
    
    });
    const Roles = mongoose.model('Roles', RolesSchema);
    
    
    const UserSchema = new Schema({
      ...
    
      roles: [{ type: mongoose.Schema.Types.ObjectId, ref: "Roles" }]
    });
    

    using the populate on userschema you can also reduce the redundancy

提交回复
热议问题