Comments (19)
This indicates that the connection to the db could not be established, as the plugin never resolves.
from fastify-mongodb.
was about to say that in your first code version you are mixin async and next, the latter version of the code should be fine.
I think it may be a firewall or something.
I would suggest to debug it with:
module.exports = fp(async function databaseConnect(fastify, opts) {
try{
await fastify.register(fastifyMongo, {
forceClose: true,
url: 'mongodb+srv://demo:[email protected]/'
})
} catch (err) {
console.log(err)
}
}, {
dependencies: ['application-config']
})
from fastify-mongodb.
You are not doing the same as this plugin, and you ignore the connection state by resolving the plugin immediately.
The below one is waiting for the connection properly.
'use strict'
const fp = require('fastify-plugin')
const mongoose = require("mongoose");
module.exports = fp(function databaseConnect(fastify, opts, done) {
mongoose.connect('mongodb+srv://demo:[email protected]/').then(() => {
console.log("connect success");
done();
}).catch(err => {
console.log("ERROR MONGOO CONNECT===>", err);
done(err);
})
}, {
name: 'plugin-mongoose',
dependencies: ['application-config']
})
from fastify-mongodb.
I tried but doing the above will get an error.
So, you would need to measure how much time you need to connect to the MongoDB Altas.
Increase the pluginTimeout to 30s or longer, if a single connection required more than 30s than it is absolutely something wrong in your network stack.
from fastify-mongodb.
The MongoDB Altas connection consist too many steps.
- DNS Resolution
- TCP / IP handshake
- Authentication
Normally, a connection will be resolved within 1 second. More than 10 second will exist in a slow network.
from fastify-mongodb.
Thank you very much. after fixing with options with pluginTimeout server it is working.
const fastify = Fastify({
disableRequestLogging: true,
logger: loggerOptions,
ajv: {
customOptions: {
removeAdditional: 'all'
}
},
connectionTimeout: 60000,
requestTimeout: 60000,
pluginTimeout: 90000
})
from fastify-mongodb.
I have configured the db on mongo lap correctly because network open is 0.0.0.0 and user + password is correct. But I don't understand why it doesn't work
from fastify-mongodb.
@Uzlopak But when working on localhost:27017 it runs again, can you help me? I just learned about fastify.
from fastify-mongodb.
I am closing the issue because there is no indication the problem related to fastify
.
You can still comment on the issue or seek for helps on the Discord channel.
From my point of view, it clearly you have some connection error to your database, please try the same connection string with MongoDB Compass
to see if your computer allowed to connect.
from fastify-mongodb.
I am 100% sure the error is from @fastify/mongodb
Here is the code I run perfectly fine with mongoose
const mongoose = require("mongoose");
(async () => {
try {
await mongoose.connect('mongodb+srv://demo:[email protected]/')
console.log("connect success");
} catch (err) {
console.log(err);
}
})()
and here is the code that runs with fastify
'use strict'
const fp = require('fastify-plugin')
const fastifyMongo = require('@fastify/mongodb')
module.exports = fp(async function databaseConnect(fastify, opts) {
fastify.register(fastifyMongo, {
forceClose: true,
url: 'mongodb+srv://demo:[email protected]/'
})
}, {
dependencies: ['application-config']
})
The result is the same as the error I posted
from fastify-mongodb.
I still get the same error.
One confusing thing is that it works with localhost:27017
while testing with mongoose new file index.js it works. If it's due to a firewall, mongoose will also not work. Because I am running on the same local machine environment.
from fastify-mongodb.
const fp = require('fastify-plugin')
const fastifyMongo = require('@fastify/mongodb')
module.exports = fp(async function databaseConnect(fastify, opts) {
try {
await fastify.register(fastifyMongo, {
forceClose: true,
url: 'mongodb+srv://demo:[email protected]/'
})
} catch (err) {
console.log("ERROR ===>",err)
}
}, {
dependencies: ['application-config']
})
Run -> ERROR ===> AvvioError [Error]: Plugin did not start in time: 'databaseConnect-auto-2'. You may have forgotten to call 'done' function or to resolve a Promise
at Timeout._onTimeout. :(
from fastify-mongodb.
I suggest you to try the official package mongodb
instead of mongoose
.
import { MongoClient } from 'mongodb'
const client = new MongoClient('mongodb+srv://demo:[email protected]/')
await client.connect()
from fastify-mongodb.
Thank. I'm just testing to find the problem and fix it.
from fastify-mongodb.
ERROR
'use strict'
const fp = require('fastify-plugin')
const fastifyMongo = require('@fastify/mongodb')
module.exports = fp(function datasourcePlugin(fastify, opts, done) {
fastify.register(fastifyMongo, {
forceClose: true,
url: 'mongodb+srv://demo:[email protected]/'
});
done();
}, {
name: 'mongodb-plugin',
dependencies: ['application-config']
})
A plugin does not fail
'use strict'
const fp = require('fastify-plugin')
const mongoose = require("mongoose");
module.exports = fp(function databaseConnect(fastify, opts, done) {
mongoose.connect('mongodb+srv://demo:[email protected]/').then(() => {
console.log("connect success");
return;
}).catch(err => {
console.log("ERROR MONGOO CONNECT===>", err);
})
done();
}, {
name: 'plugin-mongoose',
dependencies: ['application-config']
})
from fastify-mongodb.
You are not doing the same as this plugin, and you ignore the connection state by resolving the plugin immediately. The below one is waiting for the connection properly.
'use strict' const fp = require('fastify-plugin') const mongoose = require("mongoose"); module.exports = fp(function databaseConnect(fastify, opts, done) { mongoose.connect('mongodb+srv://demo:[email protected]/').then(() => { console.log("connect success"); done(); }).catch(err => { console.log("ERROR MONGOO CONNECT===>", err); done(err); }) }, { name: 'plugin-mongoose', dependencies: ['application-config'] })
I tried but doing the above will get an error.
from fastify-mongodb.
from fastify-mongodb.
What is network classification error and how to fix it. You can specify the way or area to learn how to fix it
from fastify-mongodb.
Thanks I know how to solve the problem maybe this is it. pluginTimeout
from fastify-mongodb.
Related Issues (20)
- fastify-mongodb is "eating" errors on register HOT 1
- this: Object is possibly 'undefined HOT 1
- TypeScript Example needed HOT 1
- Mongodb connection error HOT 19
- Fastify get route requires options? HOT 2
- Typescript: object is possibly undefined HOT 5
- Database Selection At Runtime HOT 4
- find() method returns events HOT 2
- Connection failes using Scalegrid.io HOT 5
- [email protected] is incompatible with newer version of [email protected]. HOT 2
- GCP Deploy using @fastify/mongodb HOT 3
- Mongodb find({}) error HOT 5
- Enable Dependabot HOT 7
- Consider re-exporting some (all?) types from mongodb HOT 1
- Update MongoDB v5 HOT 1
- Move MongoDB to peerDependencies HOT 14
- Pass variable to regex fails HOT 4
- onClose hook blocking main process HOT 7
- fastify.mongo.client.topology // TS2339: Property topology does not exist on type MongoClient HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fastify-mongodb.