I am trying to connect to a different database in mongoose using the following code:
const mongoose = require('mongoose');
const connectionOptions = { useCreateIndex: true, useNewUrlParser: true, useUnifiedTopology: true, useFindAndModify: false };
const conn = mongoose.createConnection("mongodb://localhost/db_en", connectionOptions);
const Schema = mongoose.Schema;
const priceSchema = new Schema({
fixed: {
1: { type: Number, default: 199 },
3: { type: Number, default: 499 },
6: { type: Number, default: 729 },
12: { type: Number, default: 999 }
}
});
conn.model('Price', priceSchema);
Afterwards, I aim to input data into the Price model within the newly established database:
const ggg = new conn.Price();
await ggg.save();
However, an error message is consistently being thrown:
TypeError: conn.Price is not a constructor