Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

127
Views
How to Switch DBs with Mongoose in NextJS App

I'm trying to add db switching into a NextJS app. I'm new to NextJS as a framework but have experience with NodeJS and React. In Node it would be something like this:

let db = cache.get(DB_NAME);
const Car = db.model('Car');
let allCars = await Car.find();

Where the cached value for DB_NAME is just the cached connection to a specific db. However, I keep getting the error Schema hasn't been registered for model "Car". Use mongoose.model(name, schema) even though I created the schema and required it with require('../models/Car'); in my dbConnection.js file where all of this is taking place. Just because someone will probably ask, here's my schema:

const mongoose = require('mongoose');

const CarSchema = new mongoose.Schema({
... schema stuff...
},
{ timestamps: true });

module.exports = mongoose.models.Car || mongoose.model('Car', CarSchema);

Does anyone have any experience with this? Thanks!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Figured it out. As long as you require the models, it's just db.models.Car instead of db.model('Car')

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!