@rpcbase/server 0.357.0 → 0.358.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/mongoose/index.ts
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
export * from "mongoose"
|
|
2
|
-
|
|
3
1
|
import mongoose from "mongoose"
|
|
4
2
|
import {object_id_plugin} from "./object_id_plugin"
|
|
5
3
|
|
|
6
|
-
|
|
7
4
|
mongoose.set("strictQuery", false)
|
|
8
5
|
|
|
9
6
|
mongoose.plugin(object_id_plugin)
|
|
10
7
|
|
|
11
|
-
|
|
12
8
|
export default mongoose
|
|
9
|
+
|
|
10
|
+
export * from "mongoose"
|
|
@@ -3,12 +3,24 @@ import mongoose, { Schema } from "./"
|
|
|
3
3
|
import {get_object_id} from "../get_object_id"
|
|
4
4
|
|
|
5
5
|
export const object_id_plugin = (schema: Schema) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
6
|
+
// Disable Mongoose's automatic _id field creation
|
|
7
|
+
if (!schema.options._id) {
|
|
8
|
+
schema.options._id = false
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// Add your custom _id field
|
|
12
|
+
schema.add({
|
|
13
|
+
_id: {
|
|
14
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
15
|
+
default: () => get_object_id(),
|
|
16
|
+
},
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
// Optional: Ensure the _id field is always set
|
|
20
|
+
schema.pre("save", function(next) {
|
|
21
|
+
if (!this._id) {
|
|
22
|
+
this._id = get_object_id()
|
|
23
|
+
}
|
|
24
|
+
next()
|
|
25
|
+
})
|
|
14
26
|
}
|
package/package.json
CHANGED