mongoose-elasticsearch-xp icon indicating copy to clipboard operation
mongoose-elasticsearch-xp copied to clipboard

Mongoose deprecation warning for Query.prototype.stream()

Open yvsssantosh opened this issue 6 years ago • 7 comments

screen shot 2018-03-19 at 11 05 38 am

yvsssantosh avatar Mar 19 '18 05:03 yvsssantosh

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

nodkz avatar Mar 19 '18 06:03 nodkz

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 avatar Mar 19 '18 07:03 yvsssantosh

@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

yvsssantosh avatar Mar 19 '18 07:03 yvsssantosh

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);
});

nodkz avatar Mar 19 '18 07:03 nodkz

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

yvsssantosh avatar Mar 19 '18 07:03 yvsssantosh

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

nodkz avatar Mar 19 '18 08:03 nodkz

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
}

yvsssantosh avatar Mar 19 '18 08:03 yvsssantosh