2013-12-10 46 views
0

編輯1設置TTL /到期日:使用貓鼬/ Node.js的對象

其實在進一步調查後似乎MogoDB只拿着最近的7條記錄,這是與我發送的方式做要叮叮噹噹的東西是否覆蓋了它們?

我刪除了TTL /超時的所有參考,我只看到最近的7個對象(有7個不同的對象要存儲,但隨着時間的推移有多個值)。

幫助非常感謝!

感謝

加雷思

這似乎在文檔很簡單,但我不能讓它的工作。

我創建了一個模板,它看起來像這樣:

var trackingSchema = new mongoose.Schema({ 
VehicleID: {type: String, min: 0}, 
Label: {type: String, min: 0}, 
RegNumber: {type: String, min: 0}, 
VehPosDateTimeUTC: {type: String, min: 0}, 
Latitude: {type: String, min: 0}, 
Longitude: {type: String, min: 0}, 
Heading: {type: String, min: 0}, 
SpeedKPH: {type: String, min: 0}, 
OdometerKM: {type: String, min: 0}, 
SpeedMPH: {type: String, min: 0}, 
OdometerMiles: {type: String, min: 0}, 
EventCode: {type: String, min: 0}, 
GpsStrength: {type: String, min: 0}, 
Owner: {type: String, min: 0}, 
DriverName: {type: String, min: 0}, 
DriverID: {type: String, min: 0}, 
EventCodeId: {type: String, min: 0}, 
EventType: {type: String, min: 0}, 
createdAt: { type: Date, default : Date.now, expires: '1d'}, 
}); 

然而當通過貓鼬創建的對象,進入Mongolab設置的記錄只保留最多1分鐘。

我曾嘗試createdAt也行的其他變體,如:

createdAt: { type: Date, default : Date.now, expires: 6000 } 

現在,我認爲這可能是時區的關係,但我真的不知道如何解決?

這裏是我使用的提交對象貓鼬代碼:

// Creating one vehicle record. 
var vehicleData = new trackingRecord ({ 
VehicleID: responseJSON.VehPosResponse.position_list[0].CVehiclePos[i].VehicleID[0], 
Label: responseJSON.VehPosResponse.position_list[0].CVehiclePos[i].Label[0], 
RegNumber: responseJSON.VehPosResponse.position_list[0].CVehiclePos[i].RegNumber[0], 
VehPosDateTimeUTC:responseJSON.VehPosResponse.position_list[0].CVehiclePos[i].VehPosDateTimeUTC[0], 
Latitude: responseJSON.VehPosResponse.position_list[0].CVehiclePos[i].Latitude[0], 
Longitude: responseJSON.VehPosResponse.position_list[0].CVehiclePos[i].Longitude[0], 
Heading: responseJSON.VehPosResponse.position_list[0].CVehiclePos[i].Heading[0], 
SpeedKPH: responseJSON.VehPosResponse.position_list[0].CVehiclePos[i].SpeedKPH[0], 
OdometerKM: responseJSON.VehPosResponse.position_list[0].CVehiclePos[i].OdometerKM[0], 
SpeedMPH: responseJSON.VehPosResponse.position_list[0].CVehiclePos[i].SpeedMPH[0], 
OdometerMiles: responseJSON.VehPosResponse.position_list[0].CVehiclePos[i].OdometerMiles[0], 
EventCode: responseJSON.VehPosResponse.position_list[0].CVehiclePos[i].EventCode[0], 
GpsStrength: responseJSON.VehPosResponse.position_list[0].CVehiclePos[i].GpsStrength[0], 
Owner: responseJSON.VehPosResponse.position_list[0].CVehiclePos[i].Owner[0], 
DriverName: responseJSON.VehPosResponse.position_list[0].CVehiclePos[i].DriverName[0], 
DriverID: responseJSON.VehPosResponse.position_list[0].CVehiclePos[i].DriverID[0], 
EventCodeId: responseJSON.VehPosResponse.position_list[0].CVehiclePos[i].EventCodeId[0], 
EventType: responseJSON.VehPosResponse.position_list[0].CVehiclePos[i].EventType[0] 
           }); 

// Saving it to the database. 
           vehicleData.save(function (err) {if (err) console.log ('Error on save!')}); 
+0

它表現得像一個[封頂集合](http://docs.mongodb.org/manual/core/capped-collections/)。它是一個嗎? – JohnnyHK

回答

0

找到了解決這個,它似乎是在我的測試中,我曾創造了單指標是有強制性的當前時間戳領域,這也有一個TTL設置。

所以,我不得不登錄到mongodb並刪除此索引之前,它會返回到正常行爲。每次我改變了過期時間,現在都要複製它,必須進入,刪除所有記錄並刪除索引,以便根據需要使其正常工作。

不知道這是不是一個錯誤,但它讓我好幾個小時把頭撞在牆上!

乾杯

加雷思