Connection made in submodule, searching times out, connection made in same file works. #14442
Unanswered
GerritKuilder
asked this question in
Q&A
Replies: 1 comment 1 reply
-
I might have cracked it: So in my main file I set the connection as global.db= await mongo.connect(DATABASE_URL) In my models I set my models as const track = global.db.model("track", trackSchema); This works, have to be careful to create the connection first and then load the models. Any improvements possible? Kind Regards, Gerrit Kuilder |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi All.
I have the following working (nodejs)
a) index.js
connect to mongodb in the same index file,
with a function called connect() in index.js
const model = require ( ./models/model.js
Query can run and returns results.
b) in index.js, const connection=require( ./mongoconnect.js)
same connect() function as above.
Connection is made.(plenty of logging going on)
client=await connection.connect()
However the query now fails with a timeout.
Do I need to export something extra or set a global variable?
Basically I am trying to create a npm module for local use so I can avoid duplicating code all over the place.
Any input appreciated.
Kind Regards,
Gerrit Kuilder
Beta Was this translation helpful? Give feedback.
All reactions