Answer the question
In order to leave comments, you need to log in
Collection name must be a String?
There is a 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){
if(err)console.log(err);
console.log('ok');
});
Answer the question
In order to leave comments, you need to log in
From your code, I can't figure out what you wanted to do with:
If you would like to save the model to the database, then judging by the documentation , you can do this in 2 ways (adapted to your variables):
var testModel = mongoose.model('TestModel', testdbSchema);
// способ 1
var testRecord = new TestModel({ param: 100500 });
testRecord.save(function (err) {
if (err) return handleError(err);
// saved!
})
// или способ 2
TestModel.create({ param: 100500 }, function (err, small) {
if (err) return handleError(err);
// saved!
})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question