我正在为约会应用程序构建一个Mongoose架构.
我希望每个person文档都包含对它们所访问的所有事件的引用,其中events是另一个在系统中具有自己的模型的模式.我怎样才能在架构中描述这个?
var personSchema = mongoose.Schema({
firstname: String,
lastname: String,
email: String,
gender: {type: String, enum: ["Male", "Female"]}
dob: Date,
city: String,
interests: [interestsSchema],
eventsAttended: ???
});
Run Code Online (Sandbox Code Playgroud) 我正在尝试构建注释模型包含:Reply和CommentThread.CommentThread包含Reply,而Reply可以自行递归.
/models/comment.js:
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var replySchema = new Schema({
username: String,
timestamp: { type: Date, default: Date.now },
body: String,
replies: [replySchema]
}, {_id: true});
var commentThreadSchema = new Schema({
title: String,
replies: [replySchema]
});
var Reply = mongoose.model('Reply', replySchema);
var CommentThread = mongoose.model('CommentThread', commentThreadSchema);
module.exports = {
Reply: Reply,
CommentThread: CommentThread
};
Run Code Online (Sandbox Code Playgroud)
我的错误消息是:架构阵列路径'回复'的值无效.不能replySchema将自己用作值类型?还是其他一些原因?
c:\Users\jacki_000\projects\invictusblog\node_modules\mongoose\lib\schema.js:297
throw new TypeError('Invalid value for schema Array path `'+ prefix + ke
^
TypeError: Invalid value for schema Array …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个架构子文档,但出现上面列出的错误,有问题的架构看起来像这个 Schema cassuing issues
const mongoose = require('mongoose');
const Schema = mongoose.Schema
const CharacterSchema = new Schema();
CharacterSchema.add({
name: {
type: String,
required: true
},
title: {
type: String
},
charcterClass: { // will be limited in form creation
type: String
},
level: {
type: Number
}
});
const Charcter = mongoose.model('User', CharacterSchema);
module.exports = Charcter;
Run Code Online (Sandbox Code Playgroud)
架构调用架构上面
const mongoose = require ('mongoose');
const Schema = mongoose.Schema;
const {CharacterSchema} = require(__dirname +'/CharacterModel.js');
const UserSchema = new Schema()
UserSchema.add({
name: {
type: …Run Code Online (Sandbox Code Playgroud)