Note that there are some explanatory texts on larger screens.

plurals
  1. POSetting TTL/Expires on object using Mongoose/Node.js
    primarykey
    data
    text
    <p><strong>EDIT 1</strong></p> <p>Actually after further investigation it seems that MogoDB is only holding the most recent 7 records, is this to do with the way i am sending the objects to mongoose, is it overwriting them?</p> <p>I removed all reference to TTL/Timeout and i only ever see the most recent 7 objects (there are 7 different objects to be stored, but with multiple values over time).</p> <p>Help greatly appreciated!</p> <p>Thanks</p> <p>Gareth</p> <p>This seems simple enough in the docs, but i can't get it to work.</p> <p>I have created a template which looks like this:</p> <pre><code>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'}, }); </code></pre> <p>However upon creating the objects through mongoose, into the Mongolab set the records are only kept for a maximum of 1 minute.</p> <p>I have tried other variants of the createdAt line also, such as:</p> <pre><code>createdAt: { type: Date, default : Date.now, expires: 6000 } </code></pre> <p>Now i thought this could be timezone related, but i'm not really sure how to resolve that?</p> <p>Here is the code i am using to commit the object to mongoose:</p> <pre><code>// 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!')}); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload