Nodejs-将两个不同的列表合并为一个

时间:2017-10-04 14:59:06

标签: node.js mongodb mongoose

我在猫鼬中有两个型号:

const user = mongoose.Schema({ 
    name: String,
    ...
});

const moderator = mongoose.Schema({ 
    name: String,
    ...
});

当我使用以下方式访问这些集合时:

user.find() 

我得到了用户和版主的回复列表。

我想要实现的是将这两个列表连接在一起以获得基于此模型的列表:

const myDataSchema = mongoose.Schema({ 

user: {type: Schema.Types.ObjectId, ref: 'user'},
moderator: {type: Schema.Types.ObjectId, ref: 'moderator'}

});

将设置其中一个属性(用户或主持人)。

1 个答案:

答案 0 :(得分:0)

我解决了我的问题。我没有使用猫鼬模式,而是创建了自己的对象"。我的代码:

W/TWC: TNRegNotificationCtxSession:       540533023984 | 10/04/16:57:35.623 | WARNING  | 26     | TNRegNotificationCtxSession | Could not operate with notification context in twilsock. Error 9
E/TWC: TNWebsocket:       540501275888 | 10/04/16:57:35.624 | CRITICAL | 9      | TNWebsocket | Received error while waiting for message: Net Exception

它可能不是最有效的方式,但它有效。