Closed vkupar closed 7 years ago
Do you have a more helpful repro script?
I used ES6 promises incorrectly and it was the problem. My code looked like: Model .findOne() .then() .catch()
Now I'm using .exec() method only and it works without errors
That isn't an incorrect use of promises Do you have more details?
@varunjayaraman No. I removed .then() promise and now it works very good.
@vatex I'm saying that you shouldn't have to remove .then()
. Can you show me how you used it?
MyModel
.findOne({ user: 'admin@gmail.com' }, 'email password createdAt')
then((result) => {
console.log(result);
})
.catch((error) => {
console.log(error);
});
chaining .then()
works for me:
const mongoose = require('mongoose');
const co = require('co');
mongoose.Promise = global.Promise;
const GITHUB_ISSUE = `gh-5049`;
exec()
.then(() => {
console.log('Program successful');
process.exit(0);
})
.catch(error => {
console.error(`Error: ${ error }\n${ error.stack }`);
process.exit(2);
});
function exec() {
return co(function*() {
const db = mongoose.connect(`mongodb://localhost:27017/${ GITHUB_ISSUE }`);
const schema = new mongoose.Schema({
email: String,
password: String
}, { timestamps: true });
const Model = db.model('Model', schema);
yield Model.remove({});
const doc = yield Model.create({
email: 'test@test.com',
password: 'test'
});
return Model
.findOne({ email: 'test@test.com' }, 'email password createdAt')
.then(result => {
console.log('result', result);
});
});
}
@varunjayaraman Yes but I missed this code: mongoose.Promise = global.Promise;
and maybe it was problem
Ok sounds good
BUG
{ MongoError: the limit must be positive at Function.MongoError.create (/var/app/current/node_modules/mongodb-core/lib/error.js:31:11) at /var/app/current/node_modules/mongodb-core/lib/connection/pool.js:483:72 at authenticateStragglers (/var/app/current/node_modules/mongodb-core/lib/connection/pool.js:429:16) at Connection.messageHandler (/var/app/current/node_modules/mongodb-core/lib/connection/pool.js:463:5) at Socket. (/var/app/current/node_modules/mongodb-core/lib/connection/connection.js:317:22)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)
at readableAddChunk (_stream_readable.js:176:18)
at Socket.Readable.push (_stream_readable.js:134:10)
at TCP.onread (net.js:548:20)
name: 'MongoError',
message: 'the limit must be positive',
ok: 0,
errmsg: 'the limit must be positive',
code: 15958,
codeName: 'Location15958' }
Mongoose: 4.7.5 MongoDB: 3.4 Node.js: 6.9.1
I'm trying to make [Find, Populate, Exec] I have two code, old and new. when I changed old code with new, this error appeared. In old version, "population" made by manually, with two search and in new code I use populate method to do this... I can't upgrade mongoose, because of mongoose's integrated promises is deprecated and now I don't have time to rewrite full project...