我想,我已經創造了其他模式嵌入模式,我不斷收到此錯誤:嵌入模式是給錯誤
我不能完全確定是怎麼回事錯在這裏,但我想要做什麼是存儲用戶架構內的事件架構和興趣架構的引用。如果有人能告訴我我做錯了什麼,那將是非常感謝!
編輯:我現在接收新的錯誤:
/Users/Dynee/node_modules/mongoose/lib/schema.js:421
throw new TypeError('Invalid value for schema Array path `' + prefix + key + '`');
^
TypeError: Invalid value for schema Array path `eventsHosted`
at Schema.add (/Users/Dynee/node_modules/mongoose/lib/schema.js:421:13)
at new Schema (/Users/Dynee/node_modules/mongoose/lib/schema.js:99:10)
at Object.<anonymous> (/Users/Dynee/Documents/eventure-rest-backend/Models/User.js:5:18)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/Users/Dynee/Documents/eventure-rest-backend/Models/Event.js:2:43)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
我的用戶模式
var mongoose = require('mongoose');
var EventSchema = require('../Models/Event').schema;
var InterestSchema = require('../Models/Interest').schema;
var UserSchema = new mongoose.Schema({
email: String,
password: String,
eventsHosted: [EventSchema],
eventsAttended: [EventSchema],
currentlyAttending: [EventSchema],
currentlyHosting: [EventSchema],
profileImage: String,
interests: [InterestSchema],
followers: [UserSchema],
following: [UserSchema]
});
module.exports = mongoose.model('User', UserSchema);
我的事件模式
var mongoose = require('mongoose');
var UserSchema = require('../Models/User').schema;
var EventSchema = new mongoose.Schema({
title: String,
description: String,
location: String,
attendees: [UserSchema],
date: String,
});
module.exports = mongoose.model('Event', EventSchema);
個我的興趣模式
var mongoose = require('mongoose');
var InterestSchema = new mongoose.Schema({
name: String
});
module.exports = mongoose.model('Interest', InterestSchema);
[用於模式陣列路徑無效值(的可能的複製http://stackoverflow.com/questions/30856208/invalid-value-for -schema-array-path) – Veeram
我看着那個線程,它並沒有解決我的問題。 – Dynee