collection.find(...).toArray is not a function?
See original GitHub issueI’ve implemented the example code, however when the resolver hits the data source, this error pops up
TypeError: collection.find(...).toArray is not a function
at _dataloader.default.ids (E:\test-graphql\node_modules\apollo-datasource-mongodb\dist\cache.js:31:6)
at dispatchQueueBatch (E:\test-graphql\node_modules\apollo-datasource-mongodb\node_modules\dataloader\index.js:246:22)
at dispatchQueue (E:\test-graphql\node_modules\apollo-datasource-mongodb\node_modules\dataloader\index.js:233:5)
at E:\test-graphql\node_modules\apollo-datasource-mongodb\node_modules\dataloader\index.js:70:20
at process._tickCallback (internal/process/next_tick.js:61:11)
This is how I create the data source in it’s own file
const { MongoDataSource } = require("apollo-datasource-mongodb");
class ProductPages extends MongoDataSource {
getProductPage(id) {
return this.findOneById(id);
}
}
exports.ProductPagesDataSource = new ProductPages(ProductPageModel);
This is how I add it to the ApolloServer
const { ProductPagesDataSource } = require("../graphql/schema/schema");
const app = new ApolloServer({
...
dataSources: () => ({
productPages: ProductPagesDataSource
})
});
And in the resolver I call it like this (I use graphql-compose with graphql-compose-mongoose for my schema, but that shouldn’t be an issue since I can make it work using the DataLoader package)
schemaComposer.Query.addFields({
page: ProductPageSchema.get("$findById").wrapResolve(next => rp => {
return rp.context.dataSources.productPages.getProductPage(rp.args._id);
})
});
What am I doing wrong?
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
How to solve 'TypeError: db.find(...).toArray is not a function' in ...
toArray to loop through all the documents. Whenever I run the code below, it shows TypeError: meme.find(...).toArray is not a function .
Read more >How to solve 'TypeError: db.find(…).toArray is not a function' in ...
The toArray function exists on the Cursor class from the Native MongoDB NodeJS driver. The find method in MongooseJS returns a Query object....
Read more >"cursor.toArray is not a function""collection.find() accepts at ...
I am new to node js and currently i am practicing mongoDB via mongoose 6.0. Here i am getting this error on find...
Read more >Node.js MongoDB Find - W3Schools
To select data from a collection in MongoDB, we can use the findOne() method. ... toArray(function(err, result) { if (err) throw err; console.log(result);...
Read more >cursor.toArray() — MongoDB Manual
This page documents the mongo shell method, and does not refer to the MongoDB ... that applies toArray() to the cursor returned from...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Ah, thanks—I fixed the test on latest master
On Fri, Nov 29, 2019 at 3:33 AM Jimi notifications@github.com wrote:
Not sure why, but if you can post a small reproduction repo, I can take a look ☺️