Tutorial by Examples

Importing into a default Meteor instance is fairly easy. Note that you can add a --jsonArray option if your json file is exported as an array from another system. mongoimport --db meteor --port 3001 --collection foo --file foo.json
Mongo supports database-to-database copying, which is useful if you have large databases on a staging database that you want to copy into a local development instance. // run mongod so we can create a staging database // note that this is a separate instance from the meteor mongo and minimongo ins...
Preallocation. Mongo sets aside disk-space in empty containers, so when the time comes to write something to disk, it doesn't have to shuffle bits out of the way first. It does so by a doubling algorithm, always doubling the amount of disk space preallocated until it reaches 2GB; and then each preal...
Delete the local database files. Just exit the Mongo shell, navigate to the /dbpath (wherever you set it up), and delete the files within that directory.
Did you know about the --url flag? Very handy. meteor mongo --url YOURSITE.meteor.com
They're not easily accessible. If you run the 'meteor bundle' command, you can generate a tar.gz file, and then run your app manually. Doing that, you should be able to access the mongo logs... probably in the .meteor/db directory. If you really need to access mongodb log files, set up a regular mo...
Gotta rotate those log files, or they'll eventually eat up all of your disk space. Start with some research... mongodb-log-file-growth rotate-log-files Log files can be viewed with the following command... ls /var/log/mongodb/ But to set up log-file rotation, you'll need to do the following.....
db.posts.find().forEach(function(doc){ db.posts.update({_id: doc._id}, {$set:{'version':'v1.0'}}, false, true); });
db.posts.find().forEach(function(doc){ if(doc.arrayOfObjects){ // the false, true at the end refers to $upsert, and $multi, respectively db.accounts.update({_id: doc._id}, {$unset: {'arrayOfObjects': "" }}, false, true); } });
db.originalName.renameCollection("newName" );
With the power of regex comes great responsibility.... db.posts.find({'text': /.*foo.*|.*bar.*/i})
db.posts.find().forEach(function(doc){ if(doc.oldField){ db.posts.update({_id: doc._id}, {$set:{'newField':doc.oldField}}, false, true); } });
db.posts.find().forEach(function(doc){ if(doc.commenters){ var firstCommenter = db.users.findOne({'_id': doc.commenters[0]._id }); db.clients.update({_id: doc._id}, {$set:{'firstPost': firstCommenter }}, false, true); var firstCommenter = db.users.findOne({'_id': do...
db.posts.find().forEach(function(doc){ if(doc.commentsBlobId){ var commentsBlob = db.comments.findOne({'_id': commentsBlobId }); db.posts.update({_id: doc._id}, {$set:{'comments': commentsBlob }}, false, true); } });
db.posts.find().forEach(function(doc){ if(!doc.foo){ db.posts.update({_id: doc._id}, {$set:{'foo':''}}, false, true); } });
db.posts.find().forEach(function(doc){ if(!doc.foo){ db.posts.update({_id: doc._id}, {$set:{'foo':'bar'}}, false, true); } });
db.posts.find().forEach(function(doc){ if(doc.foo === 'bar'){ db.posts.remove({_id: doc._id}); } });
db.posts.find().forEach(function(doc){ if(doc.foo === 'bar'){ db.posts.update({_id: doc._id}, {$set:{'foo':'squee'}}, false, true); } });
db.posts.find().forEach(function(doc){ if(doc.oldfield){ // the false, true at the end refers to $upsert, and $multi, respectively db.accounts.update({_id: doc._id}, {$unset: {'oldfield': "" }}, false, true); } });
db.posts.find().forEach(function(doc){ db.accounts.update({_id: doc._id}, {$set: {'_id': doc._id.str }}, false, true); });

Page 494 of 1336