I have problem with print items in console.log or res.json from database.
what am I doing wrong
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost:27017/test');
var Schema = mongoose.Schema;
var productSchema = new Schema({
title: String,
price: Number
});
var product = mongoose.model('product, productSchema');
mongoose.connect(db);
var db = 'mongodb://localhost/product';
router.get('/books', function(req, res) {
console.log('getting all products');
product.find({})
.exec(function(err, product) {
if (err) {
res.send('errror');
} else {
console.log(product);
res.json(product);
}
})
});
name of database products is : db.product
Thanks
Error: C:\Users\Turqus\Desktop\node\products\node_modules\mongoose\lib\index.js:382 throw new mongoose.Error.MissingSchemaError(name); ^ MongooseError: Schema hasn't been registered for model "product, productSchema". Use mongoose.model(name, schema) at Mongoose.model (C:\Users\Turqus\Desktop\node\products\node_modules\mongoose\lib\index.js:382:13)