#Changed to a VPS and now cant access mongodb
98 messages · Page 1 of 1 (latest)
The IP of your VPS needs to be on your Atlas instance's allowlist afaik
i can use mongodb but what i mean by that, is that i cannot access the file
to the schemas
const UserProfile = require("../../models/player")
userProfile = await UserProfile.findOne({ discordId: discorid });
MongooseError: Operation playerschemas.findOne() buffering timed out after 10000ms
and ive set this in mongodb, so that every ip can access it
Have you tried with findOne({}) to make sure it's a connection problem, not a timeout problem?
no but ill do it wait
ok this seems to work
i did this
but why cant the other codes do? all i have did is switch to a vps and put the files over there
before the vps it all worked no errors
Then your query is slow as shit, got any indexs?
you mean array or?
if im right, do you mean something like this?
No an index is a way of finding data fastet in a DB e.g. an Index on Guild Id makes finding all records for a guild faster
yes, discordId
i would do this to find a profile
Show me your user profile schema
Yea, you have no index for that schema.
What is discordId, how is it different to userId?
discordId is the discord id of someone, and userid is from the roblox user
also i can use the findone in my server.js code but not in the other ones, thats weird
I see, you'll want to make both of those an Index as otherwisr your DB is going through every record in the hop to find it in time.
An Index will make it instant
how do i do that?
guildId: { type: String, index: true },
okay, let me try
still get the same error
MongooseError: Operation playerschemas.findOne() buffering timed out after 10000ms
i got this error, since ive switched my bot to the VPS
and from the server.js code i can use the .findOne()
But when you tried the "any" find one it worked fine.
So it's got to be a speed problem.
Can you explore the DB in Atllas I assume and make sure tjhe Index has applied
my code checks if the user has a profile first, using the findOne, if not then it creates a profile for him
but i cant create a profile because the findOne is causing problems
i can use the findOne in the server.js file but not in other code ?
and why? i dont know
What's the other code, where's it live.
And where does server.js live?
the schema is in the models folder and theres a file called player
and the command is in, commands > verification > verify.js
Well the location of the file shouldn't matter
why can the server.js file use the findOne tho but the others cant ?
ive ran this code and it worked, but the command cant
I run my Bot on a NodeJS server and that also uses the mongoose code and schemas.
Are your server.js and other files running on seperate places; as in deployed to seperate ones?
i run the index.js file as same as the server.js
And via both you connect to the DB before you try to make requests?
no, only the server.js connects to the database
and the other files should be able to use the findOne then
this is only since ive switched to the VPS, if i run them on my computer they work all
i created a new file to test it and it works
but why cant the command use it ???
I assume server.js or something down the line from it imports the files you're speaking of.
What is this sat on, NodeJS?
yes
nodejs
So the non-server files "can't use it"
Did you try swapping or making a findOne(}} to see if it resolves at all on them.
i created this file if really only server.js can use it, but this file worked using findOne like i normally do
but the command which im trying to use cant
Ok so everything on the server works fine.
It's just the bot's logic that can't.
But they're run by two different initializations like you said, so the bot's code will also need to connect to the DB, which I assume its doing
yes its connecting to the database, and i can change/add/find values but the command cant, why?
i didnt change the command since it worked, and now i switched to the vps and it doesnt work anymore
Can you share the command file?
okay wait
do i just send u the part of it where it tries to do the "findOne"?
or the whole
Do the whole into a pastebin
BTW you can change this:
- const member = interaction.guild.members.cache.get(interaction.user.id);
+ const member = interaction.member;
alright thanks
So yea the code looks fine, and you tried just putting a find any and it worked in this command yea?
(sorry if already asked, just re-confirming)
no it didnt work in this command, but in a file ive made for testing the findOne if it really only works in the server.js
@ivory zealot
ive replaced the command code of a older version
and it seems to work but
i get this error:
TypeError: userProfile.save is not a function
and i think the issue was because the "await" did somtehing
Just realised you might habe a major bug, Discord Ids should always be strings, if you ever define them as numbers they will lose precision.
Yea you need to resolve the promise
okay fixed
do i add back the await or remove it?
and this is a new error now
Always need await with promises
if i add back the await tho, then i cant use the findOne in the command
Well without it you have to reply on horrid .then chaining.
2 secs
Your command function "callback" is async, there should be no reason you can't use await
ill add back the await and ill check if it still works
TypeError: userProfile.save is not a function
and this came new btw
and yeah, i cant use findOne once i add back await
So here's the problem, you need to resolve promises to ever get data from them, so if adding await causes an issur you must be using save incorrectly.
Also bare with me, I'm on a train
take ur time
but the code works without await,
It really shouldn't, least not how you expect.
I see you have
const userProfile = <findOne>;
if (userProfile) {
//do stuff as record exists
}
Problem is, a unresolved promise is truthy, so even for a missing user profile, it'll run the if
what should i do then?