February 2013 Entries

Manufacturing a MongoDB ObjectId for the past
MongoDB's ObjectId() has some nice sequential properties. One of the interesting ones is the fact that the most significant 4 bytes are a timestamp with seconds granularity. Suppose you want to query your collection for items created on or after a certain date. Since the timestamp portion can be constructed (milliseconds since epoch), and the rest can be manufactured (zero would be fine) we can now write a function to generate what the ObjectId would be or be just higher or lower than: var past = ......

Posted On Tuesday, February 19, 2013 8:04 AM | Comments (0)

MongoDB log rotation
MongoDB's engine can log quite a bit of useful detail. Whether high-transaction rate or verbose, the log can get quite large. While setting the log mode to append helps you retain the old / existing log, mongo does not currently have a facility to rotate the log at prescribed times or when a size limit is reached. In other words, the log will grow indefinitely. There are 2 ways to have the engine release current file and start a new one: SIGHUP Issue a command to mongod via a client connection The ......

Posted On Friday, February 15, 2013 5:43 AM | Comments (1)