gx
chenyc
2025-06-12 7b72ac13a83764a662159d4a49b7fffb90476ecb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
 
var assert = require('assert');
var mongo = require('mongodb');
 
var uri = process.env.MQUERY_URI || 'mongodb://localhost/mquery';
var client;
var db;
 
exports.getCollection = function(cb) {
  mongo.MongoClient.connect(uri, function(err, _client) {
    assert.ifError(err);
    client = _client;
    db = client.db();
 
    var collection = db.collection('stuff');
 
    // clean test db before starting
    db.dropDatabase(function() {
      cb(null, collection);
    });
  });
};
 
exports.dropCollection = function(cb) {
  db.dropDatabase(function() {
    client.close(cb);
  });
};