@vsaas/loopback-connector-mongodb 10.0.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/LICENSE ADDED
@@ -0,0 +1,25 @@
1
+ Copyright (c) IBM Corp. 2012,2017. All Rights Reserved.
2
+ Node module: loopback-connector-mongodb
3
+ This project is licensed under the MIT License, full text below.
4
+
5
+ --------
6
+
7
+ MIT license
8
+
9
+ Permission is hereby granted, free of charge, to any person obtaining a copy
10
+ of this software and associated documentation files (the "Software"), to deal
11
+ in the Software without restriction, including without limitation the rights
12
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
+ copies of the Software, and to permit persons to whom the Software is
14
+ furnished to do so, subject to the following conditions:
15
+
16
+ The above copyright notice and this permission notice shall be included in
17
+ all copies or substantial portions of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25
+ THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,182 @@
1
+ # @vsaas/loopback-connector-mongodb
2
+
3
+ Maintained MongoDB connector fork for LoopBack 3.
4
+
5
+ This fork stays focused on practical LB3 compatibility while simplifying the codebase:
6
+
7
+ - runtime moved to TypeScript
8
+ - modern build and test tooling (`tsdown`, `vitest`, `oxlint`)
9
+ - English-only messages
10
+ - legacy repo assets removed (`intl`, docs site, benchmarks, examples, old CI files)
11
+ - MongoDB driver kept on the `5.x` line to remain compatible with MongoDB Server `4.2`
12
+
13
+ ## Install
14
+
15
+ ```bash
16
+ npm install @vsaas/loopback-connector-mongodb
17
+ ```
18
+
19
+ ## Why `mongodb@5.x`
20
+
21
+ This fork intentionally stays on `mongodb@5.9.2`.
22
+
23
+ That keeps the connector on a conservative driver line that still works with MongoDB Server `4.2`, while avoiding the larger behavior and runtime changes introduced by newer major driver lines.
24
+
25
+ ## LoopBack 3 datasource example
26
+
27
+ ```json
28
+ {
29
+ "db": {
30
+ "name": "db",
31
+ "connector": "@vsaas/loopback-connector-mongodb",
32
+ "host": "127.0.0.1",
33
+ "port": 27017,
34
+ "database": "app",
35
+ "user": "app",
36
+ "password": "secret",
37
+ "authSource": "admin"
38
+ }
39
+ }
40
+ ```
41
+
42
+ You can also use a full connection string:
43
+
44
+ ```json
45
+ {
46
+ "db": {
47
+ "name": "db",
48
+ "connector": "@vsaas/loopback-connector-mongodb",
49
+ "url": "mongodb://app:secret@127.0.0.1:27017/app?authSource=admin"
50
+ }
51
+ }
52
+ ```
53
+
54
+ ## Supported connector settings
55
+
56
+ - `allowExtendedOperators`
57
+ - `authSource`
58
+ - `collation`
59
+ - `database`
60
+ - `disableDefaultSort`
61
+ - `enableGeoIndexing`
62
+ - `host`
63
+ - `lazyConnect`
64
+ - `password`
65
+ - `port`
66
+ - `protocol`
67
+ - `strictObjectIDCoercion`
68
+ - `url`
69
+ - `user`
70
+
71
+ The connector also forwards common MongoDB driver options such as:
72
+
73
+ - `connectTimeoutMS`
74
+ - `serverSelectionTimeoutMS`
75
+ - `socketTimeoutMS`
76
+ - `readPreference`
77
+ - `replicaSet`
78
+ - `retryWrites`
79
+ - `writeConcern`
80
+
81
+ ## Notes
82
+
83
+ - `enableGeoIndexing: true` is required for indexed `near` queries on `GeoPoint`.
84
+ - Default ids use MongoDB `ObjectId`.
85
+ - Custom collection names are supported via model settings:
86
+
87
+ ```js
88
+ {
89
+ mongodb: {
90
+ collection: 'CustomCollection';
91
+ }
92
+ }
93
+ ```
94
+
95
+ - Custom field names are supported for non-id properties:
96
+
97
+ ```js
98
+ {
99
+ title: {
100
+ type: String,
101
+ mongodb: { fieldName: 'custom_title' }
102
+ }
103
+ }
104
+ ```
105
+
106
+ LoopBack still must keep the primary key stored as `_id`; custom field names for the id property are not supported.
107
+
108
+ ## ObjectId handling
109
+
110
+ You can enforce ObjectId coercion in two common ways.
111
+
112
+ Per model:
113
+
114
+ ```js
115
+ {
116
+ options: {
117
+ strictObjectIDCoercion: true;
118
+ }
119
+ }
120
+ ```
121
+
122
+ Per property:
123
+
124
+ ```js
125
+ {
126
+ id: {
127
+ type: 'String',
128
+ id: true,
129
+ mongodb: { dataType: 'ObjectId' }
130
+ }
131
+ }
132
+ ```
133
+
134
+ ## Update operators
135
+
136
+ Set `allowExtendedOperators: true` in the datasource to allow MongoDB update operators like:
137
+
138
+ - `$set`
139
+ - `$unset`
140
+ - `$inc`
141
+ - `$max`
142
+ - `$min`
143
+ - `$mul`
144
+ - `$rename`
145
+ - `$push`
146
+ - `$pull`
147
+
148
+ Example:
149
+
150
+ ```js
151
+ Product.updateAll({ category: 'furniture' }, { $max: { price: 100 } }, cb);
152
+ ```
153
+
154
+ ## Security
155
+
156
+ The connector removes `$where` and `mapReduce` from filters by default before sending them to MongoDB.
157
+
158
+ If you really need them for trusted internal code, pass:
159
+
160
+ ```js
161
+ {
162
+ disableSanitization: true;
163
+ }
164
+ ```
165
+
166
+ ## Development
167
+
168
+ Local test defaults:
169
+
170
+ ```bash
171
+ npm test
172
+ npm run lint
173
+ npm run typecheck
174
+ ```
175
+
176
+ Test connection settings come from:
177
+
178
+ - `MONGODB_HOST`
179
+ - `MONGODB_PORT`
180
+ - `MONGODB_DATABASE`
181
+
182
+ If they are not set, the suite uses `localhost:27017`.