Search code examples
node.jselasticsearchmongooseversionmongoosastic

how to initialize mongoosastic with eleastic search 2.2.0


I am in trouble in setting mongoosastic in my node.js server. I followed the video lecture, but it does not work.

However, people said that if I downgrade elastic search version, it will be OK. But I think it should be able with elasticsearch v2.2 also.

Here is code lit.

var mongoose = require('mongoose');
var mongoosastic = require('mongoosastic');
var Schema = mongoose.Schema;

var ProductSchema = new Schema({
    category : {type : Schema.Types.ObjectId, ref : 'Category'}
    , name : String
    , price : Number
    , image : String
});

//Set Elastic Search
ProductSchema.plugin(mongoosastic, {
    hosts : [
        'localhost:9200'
    ]
});

module.exports = mongoose.model('Product', ProductSchema); 

And here is the error.

/Users/juneyoungoh/Documents/node_amazon/sample/node_modules/mongoosastic/lib/mongoosastic.js:14
  return arr.filter && arr.length === (arr.filter(item => typeof item === 'str
                                                        ^
SyntaxError: Unexpected token >
    at Module._compile (module.js:439:25)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/Users/juneyoungoh/Documents/node_amazon/sample/models/product.js:3:20)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/Users/juneyoungoh/Documents/node_amazon/sample/routes/main.js:2:15)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/Users/juneyoungoh/Documents/node_amazon/sample/server.js:83:18)
    at Module._compile (module.js:456:26)

Thanks for your help!


Solution

  • Since the latest versions of Mongoosastic it requires a Node.js version >= 4.0

    You can check something here https://github.com/mongoosastic/mongoosastic/blob/master/CHANGELOG.md