node.js 606 B

1234567891011121314151617181920212223242526272829
  1. 'use strict';
  2. const assert = require('assert');
  3. const mongo = require('mongodb');
  4. const uri = process.env.MQUERY_URI || 'mongodb://localhost/mquery';
  5. let client;
  6. let db;
  7. exports.getCollection = function(cb) {
  8. mongo.MongoClient.connect(uri, function(err, _client) {
  9. assert.ifError(err);
  10. client = _client;
  11. db = client.db();
  12. const collection = db.collection('stuff');
  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. client.close(cb);
  22. });
  23. };