Skip to content

MongoDB platform specific notes

LHCGreg edited this page Jan 20, 2014 · 4 revisions
  • mongo scripts are .js javascript files that dbsc uses the mongo command line application to run. mongo must be on your PATH.

A script might look like this:

db.createCollection('books');
db.books.ensureIndex({ name: 1 });
db.books.insert(
	[
		{
			name: 'Charlie and the Chocolate Factory',
			author: 'Roald Dahl'
		}
	]
);
  • Imports are done via mongodump/mongorestore for each collection. mongodump and mongorestore must be on your PATH to import data from another database.
  • Because a collection must be destroyed before importing with mongorestore, you will lose indexes on imported collections and get whatever indexes the source database has on the collection. This differs from every other dbsc flavor.
  • MongoDB does not have a command to create a database. When mongodbsc creates a database, here's what happens:
  1. mongodbsc ensures that the database does not already exist.
  2. If using authentication, add the authenticating user as an admin user to the new database.
  3. A temporary collection is created and dropped in the database to force the database to be created.
  4. If a -dbCreateTemplate was specified, the template will be run on the newly created database. $DatabaseName$ will be replaced with the database name.