Skip to content

Commit

Permalink
Changes after migration to Mongoose v7 (#361)
Browse files Browse the repository at this point in the history
* Changes after migration to mongoose v7

* fixup! Changes after migration to mongoose v7

* Fix typo
  • Loading branch information
nikostoulas authored Jan 29, 2024
1 parent 1372d8f commit 915d882
Showing 3 changed files with 8 additions and 7 deletions.
1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 2 additions & 2 deletions docs/integrations/mongodb.md
Original file line number Diff line number Diff line change
@@ -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.
10 changes: 5 additions & 5 deletions src/initializers/worker/worker-job.ts
Original file line number Diff line number Diff line change
@@ -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<JobDocument>;

export default mongoose.model<JobDocument, JobModel>('WorkerJob', Job);
const Job = mongoose.model<IJob>('WorkerJob', jobSchema);
export default Job;
export type JobDocument = ReturnType<typeof Job['hydrate']>;

0 comments on commit 915d882

Please sign in to comment.