The mongo Shell is an interactive JavaScript interface to MongoDB, so the solution by Leftium should work.
function objectIdWithTimestamp(timestamp) {
/* Convert string date to Date object (otherwise assume timestamp is a date) */
if (typeof(timestamp) == 'string') {
timestamp = new Date(timestamp);
}
/* Convert date object to hex seconds since Unix epoch */
var hexSeconds = Math.floor(timestamp/1000).toString(16);
/* Create an ObjectId with that hex timestamp */
var constructedObjectId = new ObjectId(hexSeconds + "0000000000000000");
return constructedObjectId
}
/* Find all documents created between Jan 12th, 2021 and Jan 13th, 2021 */
db.mycollection.find({ _id: { $gt: objectIdWithTimestamp('2021/01/12'), $lt: objectIdWithTimestamp('2021/01/13') } });
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…