MongoDB ObjectId Convertitore Timestamp ↔ ObjectId
Sapevi che ogni MongoDB ObjectId contiene un timestamp incorporato del suo momento di creazione?
Dalla shell di mongo, puoi usare getTimestamp() per recuperare il timestamp dall'ObjectId, ma non c'è una funzione incorporata per generare un ObjectId da un timestamp.
Questo convertitore online convertirà il timestamp in un ObjectId e viceversa.
ObjectId
(NOTA: non è unico, usalo solo per confronti, non per creare nuovi documenti!)
ObjectId da incollare nella shell di mongo
Time (UTC)
Anno (4 cifre)
Mese (1 - 12)
Giorno (1 - 31)
Ora (0 - 23)
Minuto (0 - 59)
Secondo (0 - 59)
Timestamp ISO
Perché generare un ObjectId da un timestamp?
Per trovare tutti i commenti creati dopo il 2013-11-01:
db.comments.find({_id: {$gt: ObjectId("5272e0f00000000000000000")}})
Javascript functions
var objectIdFromDate = function (date) { return Math.floor(date.getTime() / 1000).toString(16) + "0000000000000000"; }; var dateFromObjectId = function (objectId) { return new Date(parseInt(objectId.substring(0, 8), 16) * 1000); };