Next.js Discord

Discord Forum

[Hard issue] I am trying to pull data from my MongoDB but its not pulling anything.

Answered
Kromfohrländer posted this in #help-forum
Open in Discord
KromfohrländerOP
I have a somewhat hard issue that I cant fix. I'd like to explain in detail if someone is willing to help.

Basically,
1. User inputs info of the company they want to create on the website, company info goes to mongodb, no problem.
2. User can create a job posting, that data goes to mongodb, no problem and it shows on the page.
3. User clicks on "company" and goes to the company page where they can find more jobs of that company.
4. I want the company details to show on that page but they arent showing.

! Please let me know which tag to use here so I can use that.
Answered by Double-striped Thick-knee
He had to clear his database and workOS data. It solved the issue.
View full answer

198 Replies

KromfohrländerOP
Thank you for you interest. I have added a message saying: : (
<p>Company details are not available at this time.</p>
{companyDetails ? ( <div className='space-y-2'> <div className='flex items-center'> <User className='w-5 h-5 mr-2 text-muted-foreground' /> <span className='capitalize'> {companyDetails.newCompanyContactName} </span> </div> <div className='flex items-center'> <Mail className='w-5 h-5 mr-2 text-muted-foreground' /> <span>{companyDetails.newCompanyEmail}</span> </div> <div className='flex items-center'> <Phone className='w-5 h-5 mr-2 text-muted-foreground' /> <span>{companyDetails.newCompanyPhone}</span> </div> <div className='flex items-center'> <Map className='w-5 h-5 mr-2 text-muted-foreground' /> <span>{companyDetails.newCompanyLocation}</span> </div> {companyDetails.newCompanyWebsite && ( <div className='flex items-center'> <Globe className='w-5 h-5 mr-2 text-muted-foreground' /> <a href={companyDetails.newCompanyWebsite} target='_blank' rel='noopener noreferrer' className='text-blue-500 hover:underline' > {companyDetails.newCompanyWebsite} </a> </div> )} </div> ) : ( <p>Company details are not available at this time.</p> )}
Conditional operator.
I understand this is not enough info as there are three different pages.
Double-striped Thick-knee
can you show the query you're making to database to get company details
KromfohrländerOP
Yup
I have a Company.ts: import { Document, Schema, model, models } from 'mongoose'; export interface Company extends Document { newCompanyContactName: string; newCompanyPhone: string; newCompanyEmail: string; newCompanyLocation: string; newCompanyWebsite?: string; organizationId: string; // Add this field } const CompanySchema = new Schema<Company>({ newCompanyContactName: { type: String, required: true }, newCompanyPhone: { type: String, required: true }, newCompanyEmail: { type: String, required: true }, newCompanyLocation: { type: String, required: true }, newCompanyWebsite: { type: String }, organizationId: { type: String, required: true }, // Include the organizationId field }); // Check if the model already exists in themodelscollection export const CompanyModel = models.Company || model<Company>('Company', CompanySchema, 'companies');
Eveyrthing goes to mongodb as planned.
I get this error message by the way: Error fetching company details: Cast to ObjectId failed for value "org_01J9KB7TP4Q2AVC4QMP6167S0S" (type string) at path "_id" for model "Company"
Not sure if its corect. I put it in GPT and asked it to show me the error message as to why im not getting the data.
Double-striped Thick-knee
show the code where you've called CompanyModel.find
Where i typed Company.ts
Sorry
The entire code is here. Its not big so easy to skim through
This is new-company, where the user puts in their info about the company
Lastly this is workosactions:
Double-striped Thick-knee
thanks I'm looking into it
KromfohrländerOP
I also have a github if thats easier
Double-striped Thick-knee
  const companyDetails = (await CompanyModel.findOne({
    organizationId: org.id,
  }).lean()) as Company | null;

the screenshot you showed earlier from mongodb compass. I don't see any organizationId.
KromfohrländerOP
Right 1 sec
Sorry
This is new
So i also saw that the _id and organizationid dont match and I believe they should to show correct data?
@Kromfohrländer So i also saw that the _id and organizationid dont match and I believe they should to show correct data?
Double-striped Thick-knee
that's not required if you're not using the default _id to query
Chinese Alligator
i m not have clue to this but u should use prims orm i can say that it is very easy to talk with database
else prims handles or else orm
Chinese Alligator
i would say the day i got or used prisma never goona do the manual one like mongoose or somethung like that
@Double-striped Thick-knee are you talking about prisma?
Chinese Alligator
yes
KromfohrländerOP
Chinese Alligator
what u think about that ?
@Chinese Alligator i would say the day i got or used prisma never goona do the manual one like mongoose or somethung like that
Double-striped Thick-knee
yeah true. tho I also use drizzle. never used mongoose again
Chinese Alligator
durzzle orm right ?
it is similar to the prisma or have something else /
@Chinese Alligator i would say the day i got or used prisma never goona do the manual one like mongoose or somethung like that
KromfohrländerOP
Never heard of it.. I have no idea how to use a different database now that everything is set up..
@Kromfohrländer My github if needed: https://github.com/yasingunaydiin/yuk-yolu-full-stack-app
Double-striped Thick-knee
thanks it will be helpful
KromfohrländerOP
Thank you so much for your time guys
Chinese Alligator
if u have not so far with u r project u must see the orm prisama or drizlle whatever u like
@Chinese Alligator it is similar to the prisma or have something else /
Double-striped Thick-knee
kinda similar but more performant in complex queries
Chinese Alligator
i have error which i m solving but still i did not figure out what is casuing werror
nice
@Chinese Alligator if u have not so far with u r project u must see the orm prisama or drizlle whatever u like
Double-striped Thick-knee
@Kromfohrländer you should definitely try prisma. it's really easy to use
@Chinese Alligator if u have not so far with u r project u must see the orm prisama or drizlle whatever u like
KromfohrländerOP
I have everything set up its not a big project. Person creates job, person creates company thats all the data im storing.
Chinese Alligator
yes only need one link to connect datbase and one file for prisma that is
KromfohrländerOP
I just need the data shown on the job page thats all i need and then im done with database i think lol
@Chinese Alligator yes only need one link to connect datbase and one file for prisma that is
Double-striped Thick-knee
switching database is also easy. just need to modify the schema a little bit but code stays same
KromfohrländerOP
Im writing Prisma down but I've no idea how to set it up. that would be a differnet issue..
Chinese Alligator
not used with other ones but it supports sqlite and postsql and cockrachdb and one more i guess
Chinese Alligator
it is done by command line
u have to do nothing
Double-striped Thick-knee
@Kromfohrländer I'm going to run the project. before that, do i need any env setup?
Chinese Alligator
just see once try and then see i m not giving guarentee that u not goona face error there but it is relatvely easy compare to whole this stufff
KromfohrländerOP
Yeah theres a env file
@Chinese Alligator just see once try and then see i m not giving guarentee that u not goona face error there but it is relatvely easy compare to whole this stufff
KromfohrländerOP
Theres a lot of mongodb code written though Im a beginner at this lol. first full stack project.
Chinese Alligator
i have done mine first project 1 month ago
@Double-striped Thick-knee <@124924784055156736> I'm going to run the project. before that, do i need any env setup?
KromfohrländerOP
Can you try to run it? I guess you need the env file.
Chinese Alligator
used there prsima first time there
@Chinese Alligator used there prsima first time there
KromfohrländerOP
Gonna look into it if this doesnt work. Thank you!
Chinese Alligator
by the way what error are u facing ?
@Kromfohrländer Can you try to run it? I guess you need the env file.
Double-striped Thick-knee
I checked, looks like I need mongodb and workos key
btw what is workos used for
Chinese Alligator
so u do job or student ?
@Double-striped Thick-knee btw what is workos used for
KromfohrländerOP
WorkOS is to create the company. it stores it there
As an organizaton
Its for the auth
I use their login and registration but i really dislike it. I started the project with a tutorial vid.
Chinese Alligator
i m building a somewhere something to u making
whose tutor ?
KromfohrländerOP
Im a recent graduate but i got into front end coding two years ago
Coding with Dawid
Chinese Alligator
i nevr heard but have to see
coding with lewis and cooding with antmion i have heard and made mine first project from the code with antonio
KromfohrländerOP
I liked the look of the website he made so i just went with it as it was a Job Platform.
But i dont like his style. I dont learn anything with it and he wrote everything very complex.
Chinese Alligator
already it is subscribed somehow
i same felit from jsm one
KromfohrländerOP
I hope I can fix this issue then I can continue with making it. Ive been trying to fix it for two days
Chinese Alligator
i have solved an error for like 2 months on own
it is about cms
KromfohrländerOP
Dawid wrote a LOT of code to pull data and stuff and i dont know what to delete or to keep so Im not sure about Prisma. Id just put everything into GPT and ask it to use prisma but thats so much
Chinese Alligator
okay so u now what issue u are facing ?
in project
KromfohrländerOP
Like i said: Basically,
User inputs info of the company they want to create on the website, company info goes to mongodb, no problem.
User can create a job posting, that data goes to mongodb, no problem and it shows on the page.
User clicks on "company" and goes to the company page where they can find more jobs of that company.
I want the company details to show on that page but they arent showing.
I can also do a screen video or we can screenshare I dont mind if you have the time. @Double-striped Thick-knee
Id like that more lol
Chinese Alligator
so data not coming while rendering on the next js app frontend the data is not coming right ?
KromfohrländerOP
Yeah
Chinese Alligator
i do have after we solve u r error u can help in mine error haah
haha
The annoying thing is, the jobs do come
Chinese Alligator
then what is not coming ?
KromfohrländerOP
The company details
Chinese Alligator
okay
can u show the company details u fetching ?
Double-striped Thick-knee
@Kromfohrländer can you give a .env placeholder
@Double-striped Thick-knee <@124924784055156736> can you give a .env placeholder
KromfohrländerOP
Sorry how do i do that? Can you use my current?
Chinese Alligator
i think u shoudl screen share
if possibe
KromfohrländerOP
Ill just recreate evrything
Double-striped Thick-knee
copy paste your env without the values
KromfohrländerOP
oh
WORKOS_API_KEY=''
WORKOS_CLIENT_ID=''
WORKOS_COOKIE_PASSWORD=""
NEXT_PUBLIC_WORKOS_REDIRECT_URI=""
MONGO_URI=""
Chinese Alligator
it is written in javscript or typescript ?
Double-striped Thick-knee
typescript
Chinese Alligator
then it is good
so then there is no mess at least
so u could send me the file it fetching the company details
?
@Kromfohrländer My github if needed: https://github.com/yasingunaydiin/yuk-yolu-full-stack-app
Double-striped Thick-knee
here's the github repo he sent
KromfohrländerOP
Right
Chinese Alligator
okay soory i didnt now that
KromfohrländerOP
Np 😛
Chinese Alligator
okay and this page company one is where path ?
KromfohrländerOP
Double-striped Thick-knee
@Kromfohrländer where is this coming from. 🫠
KromfohrländerOP
I think you mean this
Chinese Alligator
i do
@Double-striped Thick-knee <@124924784055156736> where is this coming from. 🫠
KromfohrländerOP
Thats framer motion
npm install framer-motion
Chinese Alligator
yes animation libray if i m not wrong i used in mine portfolio website
KromfohrländerOP
Yup :p
Chinese Alligator
so at which line does it perfect at that file ?
Double-striped Thick-knee
it finally ran but I don't understand the language 💀
Chinese Alligator
haha
if it works dont touch it
KromfohrländerOP
Uhhm
Want me to wuickly make it all enlgihs?
Chinese Alligator
so u solved it bug ?
@Kromfohrländer Want me to wuickly make it all enlgihs?
Double-striped Thick-knee
you can tell me where to click. I have logged in
@Chinese Alligator so u solved it bug ?
Double-striped Thick-knee
no, trying to recreate
KromfohrländerOP
1 sec
Chinese Alligator
okay i guess u doing reverse engonnering
KromfohrländerOP
On the homepage giriş
Login
@Chinese Alligator okay i guess u doing reverse engonnering
Double-striped Thick-knee
yeah
@Kromfohrländer Login
Double-striped Thick-knee
i did
KromfohrländerOP
Then create a job by clicking on the big yellow button
Double-striped Thick-knee
Chinese Alligator
which language is this ?
KromfohrländerOP
turkish
you havent logged in
Click on Giris
Chinese Alligator
so u are from turkey ?
KromfohrländerOP
the login page is english
Double-striped Thick-knee
okay, whats the redirectUrl btw
KromfohrländerOP
Im originally from Holland
Chinese Alligator
i never hear of holland rather i heard of Polland
KromfohrländerOP
sorry
The Netherlands
Chinese Alligator
okay i heard netherlands
i m from india
@Kromfohrländer http://localhost:3000/api/auth/callback
Double-striped Thick-knee
owh thanks, I put ...3000/
Chinese Alligator
if u knew then
KromfohrländerOP
Yes Bharat 🙂
Chinese Alligator
wow dude
how u knew bharat thing ?
KromfohrländerOP
i do my research 🙂
@Chinese Alligator i m from india
Double-striped Thick-knee
where in india
Chinese Alligator
but i would u saying that u r code works at which point it dosnt work on file ?
u from india too ?
@Chinese Alligator u from india too ?
Double-striped Thick-knee
I'm from Bangladesh. ap kyase ho?
Chinese Alligator
okay i m from india guj
so everything okay in bangladesh ?
@Chinese Alligator so everything okay in bangladesh ?
Double-striped Thick-knee
It's better than July
KromfohrländerOP
After logging in, click on the big yellow button, then click on sirket olustur (create company), then write company name, a human name, phone number (12345) email, location and a random website.
Chinese Alligator
i heard u there is not things well so
@Chinese Alligator i heard u there is not things well so
Double-striped Thick-knee
from news I assume?
Chinese Alligator
so u have for or clone repo in the locally ?
Double-striped Thick-knee
do i need to do something in workOS dashboard @Kromfohrländer
Chinese Alligator
i guess
KromfohrländerOP
i have no idea. i can login with new account
checking
This thread has become a bit too long. Please wrap it up.
@Chinese Alligator so u have for or clone repo in the locally ?
Double-striped Thick-knee
yh, I have cloned it locally, now trying to run it
@joulev This thread has become a bit too long. Please wrap it up.
KromfohrländerOP
We arent even close to fixing my issue though. Sajid hasnt seen the issue yet
Chinese Alligator
even not i figure it really what is bug flow even
i think we should dm
@Kromfohrländer okay ?
@Chinese Alligator <@124924784055156736> okay ?
KromfohrländerOP
Sure 1 sec
Chinese Alligator
pkay
so now what is going on ?
KromfohrländerOP
@Double-striped Thick-knee Helped me out, he's a real bro. ❤️
Double-striped Thick-knee
He had to clear his database and workOS data. It solved the issue.
Answer
KromfohrländerOP
Trying to find where to mark as solved lol
@Kromfohrländer Trying to find where to mark as solved lol
Double-striped Thick-knee
lol, looks like the issue is somewhere we can't find
KromfohrländerOP
:p
I did it