0
我寫我的模式,但是當我跑我的Node.js服務器下面的錯誤顯示:MongoDB的架構 - 錯誤的createIndex調用()設置expireAt
MySchema.createIndex不是一個函數
我使用它來設置記錄的expireAt。這是我的代碼:
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var config = require('../../config.js');
var tc = new Date();
var te = tc.setSeconds(tc.getSeconds + config.EXPIRE_TOKEN_TIME.ROOM_TOKEN);
var MySchema = new Schema({
name: String,
guide: String,
leader: String,
partecipants_counter : { type: Number, default: 0},
event_counter : { type: Number, default: 0},
createAt: { type: Date, default: tc},
expireAt: { type: Date, default: te},
partecipants: [],
events : [ {
id : Number,
data: String,
user: String
} ]
});
MySchema.createIndex({ "expireAt": 1 }, { expireAfterSeconds: 180 });
module.exports = mongoose.model(config.DATA_TYPE.ROOM, MySchema);
好了,這個錯誤現在似乎是不存在的,但我可以」因爲我的變量'tc'和'te'失敗了......通過使用'Date.now',沒有轉換,但'.setSeconds'函數不可用。 – pittuzzo
expireAt希望以毫秒(Date.now)或對象(新日期())爲單位的日期? – pittuzzo
我只是想念()在獲得秒:)。謝謝 – pittuzzo