New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hi, i am unable to use the find documentation. Please help. #10610
Comments
What version of Mongoose are you using? The provided script works as expected in v5.13.7 and v6.0.0, but based on the stack trace you aren't using either of those versions. |
I have the same problem. I was using Mongoose 5.13.7 with no problems. I upgraded to 6.0.0 and this just happened. Also happens with 6.0.1. Stack: [...]\node_modules\mongoose\lib\query.js:2152
return cursor.toArray(cb);
^
TypeError: cursor.toArray is not a function
at model.Query.<anonymous> [...]\node_modules\mongoose\lib\query.js:2152:19)
at model.Query._wrappedThunk [as _find] ( [...]\node_modules\mongoose\lib\helpers\query\wrapThunk.js:27:8)
at [...]\node_modules\kareem\index.js:370:33
at processTicksAndRejections (node:internal/process/task_queues:78:11) |
This issue only happens when you call To work around this issue, use const mongoose = require('mongoose');
main().catch(err => console.log(err));
async function main() {
await mongoose.connect('mongodb://localhost:27017/fruitsDB');
const kittySchema = new mongoose.Schema({
name: String
});
const Kitten = mongoose.model('Kitten', kittySchema);
const silence = new Kitten({ name: 'Silence' });
const fluffy = new Kitten({ name: 'fluffy' });
const kittens = await Kitten.find();
console.log(kittens);
} |
@vkarpov15 So from now on do we always have to |
@lorand-horvath this is only a temporary workaround until we ship 6.0.2. Sorry for the inconvenience! |
@vkarpov15 I have just tested this and it still errors out even in 6.0.2 mongoose.connect(DB);
(async () => {
const users = await User.find();
console.log(users.length);
})().catch(err => console.log(err)); and the error is now different: If I (async () => {
await mongoose.connect(DB);
const users = await User.find();
console.log(users.length);
})().catch(err => console.log(err)); Can you please verify? I think something is not working properly in the code which was supposed to fix the issue in 6.0.2: 86f53ad I've also opened a PR to remove the |
All 3 run without issue const mongoose = require('mongoose');
const testSchema = new mongoose.Schema({
name: String
});
const Test = mongoose.model('Test', testSchema);
async function test() {
await mongoose.connect('mongodb://localhost:27017/test', {
useNewUrlParser: true,
useUnifiedTopology: true,
});
await mongoose.connection.dropDatabase();
await Test.create({name: 'Test'});
await Test.find();
console.log('Done');
}
test(); const mongoose = require('mongoose');
const testSchema = new mongoose.Schema({
name: String
});
const Test = mongoose.model('Test', testSchema);
mongoose.connect('mongodb://localhost:27017/test', {
useNewUrlParser: true,
useUnifiedTopology: true,
});
async function test() {
await mongoose.connection.dropDatabase();
await Test.create({name: 'Test'});
await Test.find();
console.log('Done');
}
test(); const mongoose = require('mongoose');
const testSchema = new mongoose.Schema({
name: String
});
const Test = mongoose.model('Test', testSchema);
mongoose.connect('mongodb://localhost:27017/test', {
useNewUrlParser: true,
useUnifiedTopology: true,
}).then((res) => console.log('THis statement has executed'));
async function test() {
await mongoose.connection.dropDatabase();
await Test.create({name: 'Test'});
await Test.find();
console.log('Done');
}
test(); |
Below script repros the issue. We'll work on a fix tomorrow 👍 const mongoose = require('mongoose');
const testSchema = new mongoose.Schema({
name: String
});
const Test = mongoose.model('Test', testSchema);
mongoose.connect('mongodb://localhost:27017/test');
async function test() {
await Test.find();
console.log('Done');
}
test(); |
@vkarpov15 I already reported it above in #10610 (comment) , including the repro script, see it again below - I guess it wasn't clear enough? mongoose.connect(DB);
(async () => {
const users = await User.find();
console.log(users.length);
})().catch(err => console.log(err)); The point is, this is still a bug and it is reproducible. |
When this fix will be released? it fixed two day ago but the 6.0.2 release was three days ago so this fix is not a part of 6.0.2 |
I tried to create the sample kittens db. I am unable to use the find function as documented.
Getting the following error message in console :
node kittens.js
TypeError: cursor.toArray is not a function
at model.Query. (/Users/shwetank/Desktop/Web Development/fruitsDBProject/node_modules/mongoose/lib/query.js:2151:19)
at model.Query._wrappedThunk [as _find] (/Users/shwetank/Desktop/Web Development/fruitsDBProject/node_modules/mongoose/lib/helpers/query/wrapThunk.js:27:8)
at /Users/shwetank/Desktop/Web Development/fruitsDBProject/node_modules/kareem/index.js:370:33
at processTicksAndRejections (internal/process/task_queues.js:77:11)
(node:30949) UnhandledPromiseRejectionWarning: MongoInvalidArgumentError: Method "collection.find()" accepts at most two arguments
at Collection.find (/Users/shwetank/Desktop/Web Development/fruitsDBProject/node_modules/mongodb/lib/collection.js:238:19)
at NativeCollection. [as find] (/Users/shwetank/Desktop/Web Development/fruitsDBProject/node_modules/mongoose/lib/drivers/node-mongodb-native/collection.js:191:33)
at NativeCollection.Collection.doQueue (/Users/shwetank/Desktop/Web Development/fruitsDBProject/node_modules/mongoose/lib/collection.js:135:23)
at /Users/shwetank/Desktop/Web Development/fruitsDBProject/node_modules/mongoose/lib/collection.js:82:24
at processTicksAndRejections (internal/process/task_queues.js:77:11)
(Use
node --trace-warnings ...
to show where the warning was created)(node:30949) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag
--unhandled-rejections=strict
(see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)(node:30949) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Please look into it.
The text was updated successfully, but these errors were encountered: