Skip to content

Instantly share code, notes, and snippets.

@lancelakey
Last active December 17, 2015 22:38
Show Gist options
  • Select an option

  • Save lancelakey/5682906 to your computer and use it in GitHub Desktop.

Select an option

Save lancelakey/5682906 to your computer and use it in GitHub Desktop.
MongoDB implicit collection creation strikes again!

"MongoDB will create collections and databases implicitly upon their first use: you do not need to create the database or collection before inserting data."

Look closely at Fri May 31 03:10:53.198 through Fri May 31 03:10:55.837 All of that work being done, time being spent, those 2+ seconds, is MongoDB performing initial setup creating the collection required to store the first document I'm adding to that collection.

So: Although "you do not need to create the database or collection before inserting data" you do need to expect that the very first document you add will include a few seconds of setup time.

# mongod run --port 27018 --quiet --nojournal --dbpath environments/test/data/mongo
Fri May 31 03:10:24.292 [initandlisten] MongoDB starting : pid=6313 port=27018 dbpath=environments/test/data/mongo 64-bit host=ip-10-172-51-100
Fri May 31 03:10:24.292 [initandlisten] db version v2.4.3
Fri May 31 03:10:24.292 [initandlisten] git version: fe1743177a5ea03e91e0052fb5e2cb2945f6d95f
Fri May 31 03:10:24.292 [initandlisten] build info: Linux ip-10-2-29-40 2.6.21.7-2.ec2.v1.2.fc8xen #1 SMP Fri Nov 20 17:48:28 EST 2009 x86_64 BOOST_LIB_VERSION=1_49
Fri May 31 03:10:24.292 [initandlisten] allocator: tcmalloc
Fri May 31 03:10:24.292 [initandlisten] options: { command: [ "run" ], dbpath: "environments/test/data/mongo", nojournal: true, port: 27018, quiet: true }
Fri May 31 03:10:24.308 [websvr] admin web console waiting for connections on port 28018
Fri May 31 03:10:24.308 [initandlisten] waiting for connections on port 27018
Fri May 31 03:10:53.198 [FileAllocator] allocating new datafile environments/test/data/mongo/test.ns, filling with zeroes...
Fri May 31 03:10:53.198 [FileAllocator] creating directory environments/test/data/mongo/_tmp
Fri May 31 03:10:53.802 [FileAllocator] done allocating datafile environments/test/data/mongo/test.ns, size: 16MB,  took 0.596 secs
Fri May 31 03:10:53.802 [FileAllocator] allocating new datafile environments/test/data/mongo/test.0, filling with zeroes...
Fri May 31 03:10:55.833 [FileAllocator] done allocating datafile environments/test/data/mongo/test.0, size: 64MB,  took 2.031 secs
Fri May 31 03:10:55.834 [FileAllocator] allocating new datafile environments/test/data/mongo/test.1, filling with zeroes...
Fri May 31 03:10:55.836 [conn2] build index test.coffeescript_example { _id: 1 }
Fri May 31 03:10:55.837 [conn2] build index done.  scanned 0 total records. 0 secs
Fri May 31 03:10:55.837 [conn2] update test.coffeescript_example query: { _id: "my_favorite_latte" } update: { _id: "favorite", flavor: "chocolate" } nscanned:0 nupdated:1
 upsert:1 keyUpdates:0 locks(micros) w:2639541 2639ms
Fri May 31 03:10:59.610 [FileAllocator] done allocating datafile environments/test/data/mongo/test.1, size: 128MB,  took 3.775 secs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment