From 915d882a915887b1cad7ed6a9d1a0e8260f9522e Mon Sep 17 00:00:00 2001 From: Nikos Kostoulas Date: Mon, 29 Jan 2024 17:22:02 +0200 Subject: [PATCH] Changes after migration to Mongoose v7 (#361) * Changes after migration to mongoose v7 * fixup! Changes after migration to mongoose v7 * Fix typo --- docs/index.md | 1 + docs/integrations/mongodb.md | 4 ++-- src/initializers/worker/worker-job.ts | 10 +++++----- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/docs/index.md b/docs/index.md index 5d3b6556..d7f97b8b 100644 --- a/docs/index.md +++ b/docs/index.md @@ -74,3 +74,4 @@ ObjectId using new mongoose. - Usage of randomUUID that is not supported in many older versions - Changes in default config: istioTraceHeaders and headerPropagation are deprecated in favor of a generic propagatedHeaders - Methods kafka.send that was deprecated is removed. Use kafka.producer.send instead +- Mongoose migrated to v7 which has breaking changes see [here](https://mongoosejs.com/docs/7.x/docs/migrating_to_7.html) diff --git a/docs/integrations/mongodb.md b/docs/integrations/mongodb.md index d8512b6f..3166498b 100644 --- a/docs/integrations/mongodb.md +++ b/docs/integrations/mongodb.md @@ -32,7 +32,7 @@ module.exports = { const mongoose = require('mongoose'); const Schema = mongoose.Schema; -const ModelScham = new Schema( +const Model = new Schema( { key: { type: String, unique: true }, ... @@ -42,7 +42,7 @@ const ModelScham = new Schema( } ); -module.exports = mongoose.model('Model', ModelScham); +module.exports = mongoose.model('Model', Model); ``` You use mongoose as you would without worrying about connection initilization. diff --git a/src/initializers/worker/worker-job.ts b/src/initializers/worker/worker-job.ts index 4138e51c..063dd5b4 100644 --- a/src/initializers/worker/worker-job.ts +++ b/src/initializers/worker/worker-job.ts @@ -1,7 +1,7 @@ import * as mongoose from 'mongoose'; const Schema = mongoose.Schema; -const Job = new Schema( +const jobSchema = new Schema( { name: { type: String, unique: true }, payload: { type: Schema.Types.Mixed, default: {} }, @@ -11,13 +11,13 @@ const Job = new Schema( { timestamps: {} } ); -export interface JobDocument extends mongoose.Document { +export interface IJob { payload: any; name: string; initialized: boolean; finished: boolean; } -export type JobModel = mongoose.Model; - -export default mongoose.model('WorkerJob', Job); +const Job = mongoose.model('WorkerJob', jobSchema); +export default Job; +export type JobDocument = ReturnType;