Collection name must be a String?

There is code:

var mongoose = require('mongoose');
var db = mongoose.connect('mongodb://localhost:27017/test').connection;

var testdbSchema = new mongoose.Schema({
 param: Number

var testdb = mongoose.model('testdb', testdbSchema, function(err){

The database connection is checked for err. But when the model is created, the console gives an error "collection name must be a String". What's wrong? Googling did not succeed.
July 9th 19 at 13:59
1 answer
July 9th 19 at 14:01
In your code, I can not understand what you wanted to do with the help of:
var testdb = mongoose.model('testdb', testdbSchema, function(err){ ...

If you would like to save the model in database, then according to the documentation you can do it 2 ways (adapted for your variables):

var testModel = mongoose.model('TestModel', testdbSchema);

// method 1
var testRecord = new TestModel({ param: 100500 }); (err) {
 if (err) return handleError(err);
 // saved!

// or method 2
TestModel.create({ param: 100500 }, function (err, small) {
 if (err) return handleError(err);
 // saved!
No as a works, thank you. Didn't even think to clean it up - kiley_Gottli commented on July 9th 19 at 14:04

Find more questions by tags MongooseNode.js