Ich habe folgendes Mungo Schema:erstellen embeded docs Mungo
'use strict';
const PostSchema = new Schema({
description: require('../fields/description'),
image: require('../fields/image'),
createdAt: require('../fields/createdAt'),
location: Location,
owner: require('../fields/owner') }, {
toObject: {
virtuals: true,
getters: true,
setters: true
},
toJSON: {
virtuals: true,
getters: true,
setters: true
} });
module.exports = mongoose.model('Post', PostSchema);
LocationSchema.js
'use strict';
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const LocationSchema = new Schema({
description: {
type: String,
required: true
},
point:{
type: [Number],
index: '2d',
required: true
},
createdAt:{
type: Date,
required: true,
default: new Date()
}
});
module.exports = mongoose.model('Location', LocationSchema);
und wenn ich meinen NodeJS Server neu starten, ich habe die folgende Fehlermeldung:
TypeError: Undefined type
Model
atlocation
Did you try nesting Schemas? You can only nest using refs or arrays.
Jemand weiß, wie man das löst?
Könnten Sie bitte weitere Informationen hier ein. Über was 'Location' ist. –
Ich füge LocationSchema hinzu – 1fabiopereira
ist das Ihre Frage => Ihre Postsammlung hat einen Ortsschlüssel und diese Orte werden in einer anderen Sammlung namens location gespeichert? –