2
Hello! I’m starting to use Mongodb with Mongoose on Nodejs and I’m finding a strange behavior when creating Models mesus on Mongodb. Example:
mongoose.connect('mongodb://localhost/db_teste');
const PersonSchema = new Schema({
name: {
first: String,
last: String
}
});
const Person = mongoose.model('Person', PersonSchema);
This code should create the Model "Person", but when I run a "show Collections" in Mongo, via prompt, in my DB "db_teste" appears "People" instead of "Person". I also created a "test" model and appeared "tests" (with an extra "s"").
What is going on?
Okay, it worked perfectly. I wonder if it is also possible to disable this behavior. Thank you
– wBB
I don’t think so, I’d have to look for better documentation. I personally have never used Mongoose (nor did I even know this question), so I can’t answer you for sure if it’s possible.
– Woss
I read the documentation and I think there is no way to disable, because in the Mongoose standard the model has a format defined as
Mongoose#model(name, [schema], [collection], [skipInit])
and can also be set the name asschema.set('collection', 'actor');
– wBB