Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

124
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda