Mongoose仅在我的数据库中插入Id。如果我调试我的代码,则填写product_data,但Product为空。怎么可能??
var ProductSchema = require('./../models/productSchema');
var Products = mongoose.model('Product',ProductSchema);
[...]
for(var i=1; i<result.length;++i){
var product_data = {
CNK : "TODO",
EAN : "TODO",
name : {nameNL: result[i]["product_name"], nameFR: "TODO"},
[...]
}
Product = new Products(product_data);
console.log(Product);
Product.save(onInsert(err));
}
productschema.js
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var ProductSchema = new Schema({
_id: Number,
CNK:String,
EAN:String,
name:{nameNL:String,nameFR:String},
[...]
}
});
答案 0 :(得分:-1)
我使用了Products.collection.insert而不是save。就像一个魅力。