Skip to content

Instantly share code, notes, and snippets.

@nesbert
nesbert / MongoDB Delete By ObjectId Creation Time.md
Last active April 15, 2023 15:24
Need a quick way to remove old (unwanted) documents from MongoDB without needing schema context.

MongoDB Delete By ObjectId Creation Time

MongoDB's ObjectId contains a timestamp, which can help you filter documents based on their creation date. To reduce the size of your collection, you can use a strategy that involves deleting or archiving old documents based on a specific date or time range.

Here's a high-level overview of the process:

  • Determine the date threshold: Decide on a date or time range beyond which you would like to remove or archive the documents. For example, you might want to remove documents older than 6 months or 1 year.
  • Query documents based on the ObjectId's timestamp: You can use MongoDB's aggregation framework or the find() method to filter documents based on the creation date embedded in the ObjectId.
@nesbert
nesbert / .bash_profile
Created June 24, 2015 14:14
My development bash, vim, etc settings for OS X.
if [ -r ~/.profile ]; then . ~/.profile; fi
case "$-" in *i*) if [ -r ~/.bashrc ]; then . ~/.bashrc; fi;; esac

Keybase proof

I hereby claim:

  • I am nesbert on github.
  • I am nesbert (https://keybase.io/nesbert) on keybase.
  • I have a public key whose fingerprint is DA38 A124 001D 303C 4BCD 4219 0DEE DC34 8890 41EE

To claim this, I am signing this object:

@nesbert
nesbert / out.sh
Created July 8, 2013 19:21
Registering a package for bower.
nhidalgo@nesberth:js $ bower register highstock-components git://github.com/nesbert/highstock.git
Registering a package will make it visible and installable via the registry.
Proceed (y/n)? y
registered highstock-components to git://github.com/nesbert/highstock.git
@nesbert
nesbert / Installation.md
Last active December 12, 2015 01:48
Guide to get Sublime Text 2 installed and running. Extended from http://1p1e1.tumblr.com/post/14262857223/9-reasons-you-must-install-sublime-text-2-code-like-a in short form. Also, included shortcuts, user & package settings.

Set Up

  1. Download latest Sublime Text 2 (Link)

  2. Install "Package Control" via console (ctrl+`)

     import urllib2,os; pf='Package Control.sublime-package'; ipp=sublime.installed_packages_path(); os.makedirs(ipp) if not os.path.exists(ipp) else None; urllib2.install_opener(urllib2.build_opener(urllib2.ProxyHandler())); open(os.path.join(ipp,pf),'wb').write(urllib2.urlopen('http://sublime.wbond.net/'+pf.replace(' ','%20')).read()); print('Please restart Sublime Text to finish installation')
    
  3. Restart Sublime Text 2

  4. OS X Command Line (Link)

@nesbert
nesbert / index.php
Created September 13, 2012 17:57
Phalcon WIP API index.php
<?php
$di = new \Phalcon\DI\FactoryDefault();
$response = new \Phalcon\Http\Response();
$response->setContentType('application/json', 'utf-8');
$di->set('response', $response);
$app = new Phalcon\Mvc\Micro();
$app->setDI($di);
@nesbert
nesbert / NewRig.md
Last active October 10, 2015 14:17
Basic info to set up a new Mac for PHP development.
@nesbert
nesbert / index.php
Created September 11, 2012 20:05
Working copy of multiple module Phalcon bootstrap (public/index.php).
<?php
/**
* Application driver class to initialize Phalcon and
* other resources.
*/
class Application extends \Phalcon\Mvc\Application
{
private static $mode = 'development'; // TODO change default to production
private static $modules = array(
'portal' => array(