mongoose 8.15.2 → 8.16.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/lib/model.js +30 -5
- package/package.json +3 -3
- package/types/models.d.ts +6 -0
package/lib/model.js
CHANGED
|
@@ -1099,11 +1099,7 @@ Model.init = function init() {
|
|
|
1099
1099
|
return;
|
|
1100
1100
|
}
|
|
1101
1101
|
|
|
1102
|
-
|
|
1103
|
-
for (const searchIndex of this.schema._searchIndexes) {
|
|
1104
|
-
results.push(await this.createSearchIndex(searchIndex));
|
|
1105
|
-
}
|
|
1106
|
-
return results;
|
|
1102
|
+
return await this.ensureSearchIndexes();
|
|
1107
1103
|
};
|
|
1108
1104
|
const _createCollection = async() => {
|
|
1109
1105
|
let autoCreate = utils.getOption(
|
|
@@ -1792,6 +1788,35 @@ function _ensureIndexes(model, options, callback) {
|
|
|
1792
1788
|
}
|
|
1793
1789
|
}
|
|
1794
1790
|
|
|
1791
|
+
/**
|
|
1792
|
+
* Creates all [Atlas search indexes](https://www.mongodb.com/docs/atlas/atlas-search/create-index/) defined in this model's schema.
|
|
1793
|
+
* This function only works when connected to MongoDB Atlas.
|
|
1794
|
+
*
|
|
1795
|
+
* #### Example:
|
|
1796
|
+
*
|
|
1797
|
+
* const schema = new Schema({
|
|
1798
|
+
* name: String,
|
|
1799
|
+
* description: String
|
|
1800
|
+
* });
|
|
1801
|
+
* schema.searchIndex({ name: 'test', definition: { mappings: { dynamic: true } } });
|
|
1802
|
+
* const Product = mongoose.model('Product', schema);
|
|
1803
|
+
*
|
|
1804
|
+
* // Creates the search index defined in the schema
|
|
1805
|
+
* await Product.createSearchIndexes();
|
|
1806
|
+
*
|
|
1807
|
+
* @api public
|
|
1808
|
+
* @return {Promise} resolves to the results of creating the search indexes
|
|
1809
|
+
*/
|
|
1810
|
+
|
|
1811
|
+
Model.createSearchIndexes = async function createSearchIndexes() {
|
|
1812
|
+
_checkContext(this, 'createSearchIndexes');
|
|
1813
|
+
const results = [];
|
|
1814
|
+
for (const searchIndex of this.schema._searchIndexes) {
|
|
1815
|
+
results.push(await this.createSearchIndex(searchIndex));
|
|
1816
|
+
}
|
|
1817
|
+
return results;
|
|
1818
|
+
};
|
|
1819
|
+
|
|
1795
1820
|
/**
|
|
1796
1821
|
* Schema the model uses.
|
|
1797
1822
|
*
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mongoose",
|
|
3
3
|
"description": "Mongoose MongoDB ODM",
|
|
4
|
-
"version": "8.
|
|
4
|
+
"version": "8.16.0",
|
|
5
5
|
"author": "Guillermo Rauch <guillermo@learnboost.com>",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"mongodb",
|
|
@@ -20,9 +20,9 @@
|
|
|
20
20
|
"type": "commonjs",
|
|
21
21
|
"license": "MIT",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"bson": "^6.10.
|
|
23
|
+
"bson": "^6.10.4",
|
|
24
24
|
"kareem": "2.6.3",
|
|
25
|
-
"mongodb": "~6.
|
|
25
|
+
"mongodb": "~6.17.0",
|
|
26
26
|
"mpath": "0.9.0",
|
|
27
27
|
"mquery": "5.0.0",
|
|
28
28
|
"ms": "2.1.3",
|
package/types/models.d.ts
CHANGED
|
@@ -356,6 +356,12 @@ declare module 'mongoose' {
|
|
|
356
356
|
*/
|
|
357
357
|
createSearchIndex(description: SearchIndexDescription): Promise<string>;
|
|
358
358
|
|
|
359
|
+
/**
|
|
360
|
+
* Creates all [Atlas search indexes](https://www.mongodb.com/docs/atlas/atlas-search/create-index/) defined in this model's schema.
|
|
361
|
+
* This function only works when connected to MongoDB Atlas.
|
|
362
|
+
*/
|
|
363
|
+
createSearchIndexes(): Promise<string[]>;
|
|
364
|
+
|
|
359
365
|
/** Connection the model uses. */
|
|
360
366
|
db: Connection;
|
|
361
367
|
|