我正在使用MongoDB(mongoose)和Nodejs创建聊天应用程序。如下所示,我有一个mongoose允许的架构,但 storeSchema 中的用户需要是一个字符串数组(用户名)。这是正确的方法吗?
"use strict";
var express = require('express');
var mongoose = require('mongoose');
var userSchema = new mongoose.Schema({
user: String
});
var messageSchema = new mongoose.Schema({
msg: String
});
var storeSchema = new mongoose.Schema({
users: [userSchema], // needs to be an array of users
channels: {
general: {
messages: [messageSchema]
},
videogames: {
messages: [messageSchema]
},
programming: {
messages: [messageSchema]
},
other: {
messages: [messageSchema]
}
}
});
var User = mongoose.model('User', userSchema);
var Message = mongoose.model('Message', messageSchema);
var Storage = mongoose.model('Storage', storeSchema);
module.exports = {
User: User,
Message: Message,
Storage: Storage
}
答案 0 :(得分:0)
如果您希望users
成为用户名字符串数组,请在storeSchema
中将其定义为:
users: [String]