mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 11:35:55 +01:00
closes #6499
This commit is contained in:
@@ -59,7 +59,7 @@
|
||||
"material-design-lite": "^1.3.0",
|
||||
"mime": "^2.2.0",
|
||||
"mkdirp": "^0.5.1",
|
||||
"mongodb": "2.2.33",
|
||||
"mongodb": "3.0.8",
|
||||
"morgan": "^1.9.0",
|
||||
"mousetrap": "^1.6.1",
|
||||
"mubsub": "^1.4.0",
|
||||
|
||||
@@ -10,6 +10,7 @@ var _ = require('lodash');
|
||||
var semver = require('semver');
|
||||
var prompt = require('prompt');
|
||||
var db;
|
||||
var client;
|
||||
|
||||
var mongoModule = module.exports;
|
||||
|
||||
@@ -107,13 +108,13 @@ mongoModule.init = function (callback) {
|
||||
|
||||
connOptions = _.merge(connOptions, nconf.get('mongo:options') || {});
|
||||
|
||||
mongoClient.connect(connString, connOptions, function (err, _db) {
|
||||
mongoClient.connect(connString, connOptions, function (err, _client) {
|
||||
if (err) {
|
||||
winston.error('NodeBB could not connect to your Mongo database. Mongo returned the following error', err);
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
db = _db;
|
||||
client = _client;
|
||||
db = client.db();
|
||||
|
||||
mongoModule.client = db;
|
||||
|
||||
@@ -264,7 +265,7 @@ function getCollectionStats(db, callback) {
|
||||
|
||||
mongoModule.close = function (callback) {
|
||||
callback = callback || function () {};
|
||||
db.close(function (err) {
|
||||
client.close(function (err) {
|
||||
callback(err);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -108,7 +108,7 @@ module.exports = function (db, module) {
|
||||
return getFromCache();
|
||||
}
|
||||
|
||||
db.collection('objects').find({ _key: { $in: nonCachedKeys } }, { _id: 0 }).toArray(function (err, data) {
|
||||
db.collection('objects').find({ _key: { $in: nonCachedKeys } }, { projection: { _id: 0 } }).toArray(function (err, data) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
@@ -105,7 +105,7 @@ module.exports = function (db, module) {
|
||||
db.collection('objects').aggregate([
|
||||
{ $match: { _key: key } },
|
||||
{ $project: { count: { $size: '$array' } } },
|
||||
], function (err, result) {
|
||||
]).toArray(function (err, result) {
|
||||
callback(err, Array.isArray(result) && result.length && result[0].count);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -152,7 +152,8 @@ module.exports = function (db, module) {
|
||||
if (!key) {
|
||||
return callback(null, []);
|
||||
}
|
||||
db.collection('objects').findOne({ _key: key }, { members: 1 }, { _id: 0, _key: 0 }, function (err, data) {
|
||||
|
||||
db.collection('objects').findOne({ _key: key }, { projection: { _id: 0, _key: 0 } }, function (err, data) {
|
||||
callback(err, data ? data.members : []);
|
||||
});
|
||||
};
|
||||
@@ -161,7 +162,7 @@ module.exports = function (db, module) {
|
||||
if (!Array.isArray(keys) || !keys.length) {
|
||||
return callback(null, []);
|
||||
}
|
||||
db.collection('objects').find({ _key: { $in: keys } }, { _id: 0, _key: 1, members: 1 }).toArray(function (err, data) {
|
||||
db.collection('objects').find({ _key: { $in: keys } }, { projection: { _id: 0 } }).toArray(function (err, data) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
@@ -179,7 +179,7 @@ module.exports = function (db, module) {
|
||||
{ $group: { _id: { _key: '$_key' }, count: { $sum: 1 } } },
|
||||
{ $project: { _id: 1, count: '$count' } },
|
||||
];
|
||||
db.collection('objects').aggregate(pipeline, function (err, results) {
|
||||
db.collection('objects').aggregate(pipeline).toArray(function (err, results) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ module.exports = function (db, module) {
|
||||
{ $group: { _id: null, count: { $sum: 1 } } },
|
||||
];
|
||||
|
||||
db.collection('objects').aggregate(pipeline, function (err, data) {
|
||||
db.collection('objects').aggregate(pipeline).toArray(function (err, data) {
|
||||
callback(err, Array.isArray(data) && data.length ? data[0].count : 0);
|
||||
});
|
||||
};
|
||||
@@ -88,7 +88,7 @@ module.exports = function (db, module) {
|
||||
}
|
||||
pipeline.push({ $project: project });
|
||||
|
||||
db.collection('objects').aggregate(pipeline, function (err, data) {
|
||||
db.collection('objects').aggregate(pipeline).toArray(function (err, data) {
|
||||
if (err || !data) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ module.exports = function (db, module) {
|
||||
var project = { _id: 0, count: '$count' };
|
||||
pipeline.push({ $project: project });
|
||||
|
||||
db.collection('objects').aggregate(pipeline, function (err, data) {
|
||||
db.collection('objects').aggregate(pipeline).toArray(function (err, data) {
|
||||
callback(err, Array.isArray(data) && data.length ? data[0].count : 0);
|
||||
});
|
||||
};
|
||||
@@ -66,7 +66,7 @@ module.exports = function (db, module) {
|
||||
}
|
||||
pipeline.push({ $project: project });
|
||||
|
||||
db.collection('objects').aggregate(pipeline, function (err, data) {
|
||||
db.collection('objects').aggregate(pipeline).toArray(function (err, data) {
|
||||
if (err || !data) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user