Hi guys, I created a small project to learn. I created a connection to 2 DB, and I have 2 schemas with the same name. I can add multiples docs on the first DB but only one on the second because I got the error
MongoServerError: E11000 duplicate key error collection: DB1.questions index: themes_1 dup key: { themes: null }
I created 2 Schemas, 1 per DB and they are different
Schema 1
const mongoose = require("mongoose");
const Schema = mongoose.Schema;
const conn = require('../../config/mongooseSetup');
const questionShema = new Schema({
question: { type: String, required: true, unique: true },
lang: { type: String, default: "en" }
});
module.exports = conn.DB1.model("question", questionShema);
Schema 2
const questionShema = new Schema({
question: { type: String, required: true },
lang: { type: String, default: "en" },
themes: [
{ type: Schema.Types.ObjectId, ref: "theme", required: true },
]
});
module.exports = conn.DB2.model("question", questionShema);
Is this possible in MongoDB?, if I use a different schema name on DB2 works like a charm