среда, 3 сентября 2014 г.

MongoDB

Удалить по дате создания
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 = ObjectId(hexSeconds + "0000000000000000");

    return constructedObjectId
}
db.users.remove({ _id: { $gt: objectIdWithTimestamp('2014/07/15') } })

http://stackoverflow.com/questions/8749971/can-i-query-mongodb-objectid-by-date


Комментариев нет:

Отправить комментарий