I’m trying to create a document with a TTL
I got error MongoError: Values in v:2 index key pattern cannot be of type date. Only numbers > 0, numbers < 0, and strings are allowed.
Don’t know what i should do.
Meteor.startup(() => {
LaptopConnections._ensureIndex({ creationDate:new Date() }, { expireAfterSeconds:120});// Will delete the collection after two minutes,
});
Meteor.methods({
create_laptopconnection (lap_id) {
check(lap_id, String);
if (!LaptopConnections.findOne({_id: lap_id})) {
/* Insert a new Brief of the laptop */
LaptopConnections.insert({
_id: lap_id,
creationDate: new Date()
});
}else{
LaptopConnections.update({_id: lap_id},{upsert:true},{
$set: {
"state.date": Date.now(),
creationDate: Date.now()
}
}
),{ multi: true };
}
}
})
laptop.js ( collections )
LaptopConnections = new Mongo.Collection('laptopconnection');
let LaptopConnectionSchema = new SimpleSchema({
creationDate : {
type: Date,
label: "Date when the laptop was created",
// defaultValue: new Date()
autoValue: function(){
return new Date;
}
},
"state.date" : {
type: Date,
label: "time when the laptop was created",
autoValue: function(){
return new Date;
}
}
}
,{timestamps: true}
)
LaptopConnections.attachSchema(LaptopConnectionSchema)