jbdemonte / mongoose-elasticsearch-xp

A mongoose plugin that indexes models into Elasticsearch 2 / 5 / 6 and 7
93 stars 34 forks source link

Mongoose deprecation warning for Query.prototype.stream() #42

Open yvsssantosh opened 6 years ago

yvsssantosh commented 6 years ago
screen shot 2018-03-19 at 11 05 38 am
nodkz commented 6 years ago

Which version of mongoose do you use?

With >5.0.0 this message should disappear code: https://github.com/jbdemonte/mongoose-elasticsearch-xp/blob/master/lib/index.js#L341

yvsssantosh commented 6 years ago

Oh, that seems to be the problem. I'm currently using mongoose 4.9.0 because of which that depreciation warning might have come up.

I'll change the version and update it here

yvsssantosh commented 6 years ago

@nodkz Can you please help me out on what to use as a replacement for .on()

i.e. previously, we have been using Model.on('es-bulk-error', function( err ){ console.log('Error : ', err) }) which is showing another warning,

UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): TypeError: Cannot read property 'on' of undefined

screen shot 2018-03-19 at 1 07 36 pm
nodkz commented 6 years ago

Provide detailed console output for your rejection.

For this, you need to add following code to your app:

process.on('unhandledRejection', error => {
  console.log('unhandledRejection');
  console.dir(error);
});
yvsssantosh commented 6 years ago

This is what it shows on type error,

TypeError: Cannot read property 'on' of undefined
    at utils.run (/app/node_modules/mongoose-elasticsearch-xp/lib/index.js:377:12)
    at new Promise (<anonymous>)
    at Object.module.exports.run (/app/node_modules/mongoose-elasticsearch-xp/lib/utils.js:30:12)
    at Function.synchronize [as esSynchronize] (/app/node_modules/mongoose-elasticsearch-xp/lib/index.js:327:16)
    at Object.<anonymous> (/app/src/models/product.js:81:22)     // Here I have the esSynchronize() method
    at Module._compile (module.js:643:30)
    at Object.Module._extensions..js (module.js:654:10)
    at Module.load (module.js:556:32)
    at tryModuleLoad (module.js:499:12)
    at Function.Module._load (module.js:491:3)
    at Module.require (module.js:587:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/app/src/repository/product.js:2:34)
    at Module._compile (module.js:643:30)
    at Object.Module._extensions..js (module.js:654:10)
    at Module.load (module.js:556:32)
screen shot 2018-03-19 at 1 23 27 pm
nodkz commented 6 years ago

It may be a problem with wrong bulker option which you provide for mongoose-elasticsearch-xp: https://github.com/jbdemonte/mongoose-elasticsearch-xp/blob/master/lib/index.js#L343

yvsssantosh commented 6 years ago

Yeah, I thought the same, this is actually my models.py

'use strict'

const Joi = require('joi')
const Mongoose = require('mongoose')
const Joigoose = require('joigoose')(Mongoose)

const MongoosasticXP = require('mongoose-elasticsearch-xp')

let SampleJoi = Joi.object().keys({
  //...
  //...
  // Some schema
})

let mongooseSampleSchema = Joigoose.convert(SampleJoi)

let mongooseSampleMiddlewareSchema = new Mongoose.Schema(mongooseSampleSchema)

//
// Some config for elasticsearch
//

let SampleDb = Mongoose.model('Sample', mongooseSampleMiddlewareSchema)

SampleDb.on('es-bulk-error', function (err) {
  console.log(err)
  throw Error(err)
})

SampleDb.esSynchronize().then(function (response) { // Here is where the error is being shown in my code.... i.e. where the error propagation starts
  console.log('Indexed all documents!')
})

module.exports = {
  SampleJoi,
  SampleDb: SampleDb
}