mongoose model.save()无效

时间:2018-01-20 14:31:26

标签: save mongoose-schema

//我只是尝试将数据提供给mongo表,但.save()函数无法正常工作,也没有给出任何错误 RUN:终端

  

node feed.js

<!-- this is my product model product.js-->

var mongoose = require('mongoose');
var Schema   = mongoose.Schema;
var productSchema = new Schema({
    image : { type: String,required: true },
    title : { type: String,required: true },
    description : { type: String,required: true },
    price : { type: Number,required: true }
});
module.exports = mongoose.model('Product', productSchema);

<!-- this my seeder file feed.js to feed data on mongo table  -->

var Product = require('../models/product');
var mongoose = require('mongoose');
mongoose.createConnection("mongodb://127.0.0.1:27017/shopping");
var products = new Product({
     image : "post1jpg",
    title : "Lenevo Laptop",
    description : "long description here",
    price : '3500'
     });
 products.save(function(err){ <!-- this section not working -->
    if (err){ throw err; }
    }); 

0 个答案:

没有答案