node.js 624 B

123456789101112131415161718192021222324252627282930
  1. var assert = require('assert')
  2. var slice = require('sliced')
  3. var mongo = require('mongodb')
  4. var utils = require('../../').utils;
  5. var uri = process.env.MQUERY_URI || 'mongodb://localhost/mquery';
  6. var db;
  7. exports.getCollection = function (cb) {
  8. mongo.Db.connect(uri, function (err, db_) {
  9. assert.ifError(err);
  10. db = db_;
  11. var collection = db.collection('stuff');
  12. collection.opts.safe = true;
  13. // clean test db before starting
  14. db.dropDatabase(function () {
  15. cb(null, collection);
  16. });
  17. })
  18. }
  19. exports.dropCollection = function (cb) {
  20. db.dropDatabase(function () {
  21. db.close(cb);
  22. })
  23. }