Open rsadyhov opened 7 years ago
Hi @rsadyhov ! Could you post a executable snippet of your code using mongo-in-memory and causing that error so I can reproduce it and find out the problem?
Hello,
I suppose it must be some versioning because this code doesn't work:
return dbKeyModel[dbKey].aggregate(query);
and this works fine for me:
return new Promise((resolve, reject) => {
dbKeyModel[dbKey].aggregate(query).cursor({
batchSize: 2500,
async: true
}).exec().then((cursor) => {
let result = {};
cursor
.on('error', function(err) {
reject(err);
})
.on('data', function(data) {
result = Object.assign({}, result, data);
})
.on('end', function() {
resolve(Object.keys(result).length === 0 ? result : [result]);
});
});
Where dbKeyModel[dbKey]
is next:
const mongoose = require('mongoose');
let someSchema = new mongoose.Schema({
_id: String,
sometId: {type: String, required: true},
........
someNumber: Number
});
let SomeModel = mongoose.model('SomeModel', someSchema);
module.exports = SomeModel;
Getting next error for aggregation operation:
"MongoError: The 'cursor' option is required, except for aggregation explain\n at Function.MongoError.create (api/node_modules/mongodb-core/lib/error.js:31:11)\n at /api/node_modules/mongodb-core/lib/connection/pool.js:489:72\n at authenticateStragglers (api/node_modules/mongodb-core/lib/connection/pool.js:435:16)\n at Connection.messageHandler (api/node_modules/mongodb-core/lib/connection/pool.js:469:5)\n at Socket.<anonymous> (/api/node_modules/mongodb-core/lib/connection/connection.js:321:22)\n at emitOne (events.js:96:13)\n at Socket.emit (events.js:188:7)\n at readableAddChunk (_stream_readable.js:176:18)\n at Socket.Readable.push (_stream_readable.js:134:10)\n at TCP.onread (net.js:548:20)"
List of dependencies: