Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

125
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda