0
votes

i have created model for the mongo collection like below. but it was giving me the collection output which saved in mongoDB.

var mongoose = require('mongoose'),
Schema = mongoose.Schema({
    name: {
        type: String
    },
    age: {
        type: Number
    },
})
module.exports = mongoose.model('container', Schema);}

But later when i changed the last line of the code which is

"module.exports = mongoose.model('container', Schema);"

to

"module.exports = mongoose.model('container', Schema, 'container');"

it worked properly. I check the mongoose document they say to use the previous line, then why didn't it worked.

1

1 Answers

0
votes

your problem seems to be from using "Schema" as a variable name

var ContainerSchema = new mongoose.Schema({
    ...
});

and exporting

module.exports = mongoose.model("Container", ContainerSchema);

would work.