mongoose-elasticsearch-xp
mongoose-elasticsearch-xp copied to clipboard
Conflict with NestJS
trafficstars
If I add the MEXP plugin to my Mongoose schema, then my Nest server can't start and crashes with the following error :
.\node_modules\@nestjs\mongoose\mongoose.utils.js:4 return
${JSON.stringify(model)}Model; ^TypeError: Converting circular structure to JSON at JSON.stringify (
) at Object.getModelToken (.\node_modules\@nestjs\mongoose\mongoose.utils.js:4:20) at Object.exports.InjectModel (.\node_modules\@nestjs\mongoose\mongoose.decorators.js:5:67)
If I do not add the plugin, the server works and starts.
I have used MEXP for years in other Node projects, it has always worked. Now I'm switching to NestJS and I get this error. Here's the relevant code
const mexp = require("mongoose-elasticsearch-xp"),
AdSchema = new mongoose.Schema({ ........ });
AdSchema.plugin(mexp, { // If I comment out these lines, the code works.
client: new elasticsearch.Client(esOptions),
hosts: ['localhost:9200']
});
Using dependencies :
"dependencies": {
"@nestjs/common": "^4.6.6",
"@nestjs/core": "^4.6.6",
"@nestjs/microservices": "^4.6.6",
"@nestjs/mongoose": "^3.0.1",
"@nestjs/testing": "^4.6.6",
"@nestjs/websockets": "^4.6.6",
"bluebird": "^3.5.1",
"dotenv": "^5.0.1",
"elasticsearch": "^14.2.2",
"express": "^4.16.3",
"mongoose": "^5.0.16",
"mongoose-elasticsearch-xp": "^5.4.1",
"reflect-metadata": "^0.1.12",
"rxjs": "^5.5.6"
}