0
私は2つのコレクション:bookings
とtimeslots
を持っています。MongoDBの2つの異なるコレクション間のキー値の交差
models/booking.js:
var mongoose = require ('../config/db');
var Schema = require('mongoose').Schema;
var ObjectId = Schema.ObjectId;
var bookingSchema = new Schema({
start: {
type: Number,
required: true
},
end: {
type: Number,
required: true
},
date: {
type: Date,
required: true,
default: Date.now
}
});
models/time_slot.js:
var mongoose = require ('../config/db');
var Schema = require('mongoose').Schema;
var ObjectId = Schema.ObjectId;
var timeSlotSchema = new Schema({
start: {
type: Number,
required: true
},
end: {
type: Number,
required: true
},
date: {
type: Number,
required: true,
default: Time.Today
},
enabled: {
type: Boolean,
required: true,
default: true,
},
pickup: {
type: Boolean,
required: true,
default: true,
}
});
の両方が共通のフィールドstart
を持っています。私はにstart
の値が入っているコレクションtimeslots
からエントリを取得したいと考えています。
私が試してみました:
controllers/time_slot.js:
var timeSlotModel = require('../models/time_slot').model;
var Booking = require('./booking');
Booking.getBookings({}, function(err, bookings) {
if (err) {
console.error(err);
} else {
timeSlotModel.find({start: bookings.start}, function(err, slots) {
if (err) {
console.error(err);
} else {
return next(null, slots);
}
}
}
をしかし、それは当然、動作しない、と私はエラーを取得:
MongooseError: Cast to number failed for value "undefined" at path "start"
can y私たちも 'getBookings'メソッドを見せてくれますか? – drinchev
は予約を予約していますか?そのような方法で.startはフィールドではないからです。 –
'TimeSlot'モデルを表示できますか? – ZeMoon