我不能在这里解决这个问题。我已经尝试创建Map,以便我的代码可以与es6x兼容,但仍然无法解决问题。我的代码可能有一些问题,但我无法确定确切的问题。
这是我的index.js代码
Product.createMapping(
{
"products": {
"properties": {
"category": {
"type": "keyword"
},
"name": {
"type": "text"
},
"price": {
"type": "double"
},
"image": {
"type": "text"
}
}
}
}, function(err, mapping){
if (err) {
console.log('error creating mapping');
console.log(err);
}
else{
console.log('Mapping successfully created');
console.log(mapping);
}
});
var data = Product.synchronize();
var count = 0;
data.on('date', function(){
count++;
});
data.on('close', function(){
console.log('Indexed' + count + 'Documents');
});
data.on('error', function(err){
console.log(err);
});
这是我的product.js代码。
var mongoose = require('mongoose');
var mongoosastic = require('mongoosastic');
var Schema = mongoose.Schema;
var schema = new Schema({
category: {type: Schema.Types.ObjectId, ref: 'Category'},
image: {type: String, required: true},
name: {type: String, required: true},
price: {type: Number, required: true}
});
schema.plugin(mongoosastic,{
hosts: [
'localhost:9200'
]
});
module.exports = mongoose.model('Product', schema);
1条答案
按热度按时间mspsb9vt1#
您必须在模式声明中声明esu类型,如下所示: