2012-11-12 10 views

risposta

43

Credo che ObjectId abbia un metodo getTimestamp(); per esempio.

_id.getTimestamp() 
1

Se si esegue questo si otterrà il timestamp

console.log(new mongoose.Types.ObjectId().getTimestamp()); 

ad es.

Fri Nov 16 2012 17:20:14 GMT+0000 (GMT) 
4

è possibile creare un 'creato' immobile virtual sullo schema mangusta che utilizza il _id per ottenere il timestamp di creazione. Basta aggiungere:

YourMongooseSchema.virtual('created').get(function() { 
    if (this["_created"]) return this["_created"]; 
    return this["_created"] = this._id.getTimestamp(); 
}); 
0
_id.getTimestamp() 

non funziona per me, ma

_id.Time() 

funziona perfetto

Problemi correlati