Skip to content

Commit a457b3e

Browse files
committed
fix: bumped deps, updated docs Promise.each usage
1 parent 5e30720 commit a457b3e

File tree

4 files changed

+3034
-2777
lines changed

4 files changed

+3034
-2777
lines changed

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
* [Install](#install)
1616
* [Usage](#usage)
17+
* [Static Methods](#static-methods)
1718
* [Options](#options)
1819
* [Slug Tips](#slug-tips)
1920
* [Slug Uniqueness](#slug-uniqueness)
@@ -132,6 +133,28 @@ This function accepts an `_id` and `str` argument. The `_id` being the ObjectID
132133
This function is used internally by the plugin to recursively ensure uniqueness.
133134

134135

136+
## Static Methods
137+
138+
If you have to write a script to automatically set slugs across a collection, you can use the `getUniqueSlug` static method this package exposes on models.
139+
140+
For example, if you want to programmatically set all blog posts to have slugs, run this script (note that you should run the updates serially as the example shows to prevent slug conflicts):
141+
142+
```js
143+
const Promise = require('bluebird'); // exposes `Promise.each`
144+
145+
const BlogPost = require('../app/models/blog-post.js');
146+
147+
(async () => {
148+
const blogPosts = await BlogPost.find({}).lean()exec();
149+
await Promise.each(blogPosts, async blogPost => {
150+
blogPost.slug = null;
151+
blogPost.slug = await BlogPost.getUniqueSlug(blogPost.title);
152+
return blogPost.save();
153+
}));
154+
})();
155+
```
156+
157+
135158
## Options
136159

137160
Here are the default options passed to the plugin:

package.json

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,30 @@
1111
"Nick Baugh <niftylettuce@gmail.com> (http://niftylettuce.com/)"
1212
],
1313
"dependencies": {
14-
"lodash": "^4.17.10",
14+
"lodash": "^4.17.11",
1515
"speakingurl": "^14.0.1",
16-
"underscore.string": "^3.3.4"
16+
"underscore.string": "^3.3.5"
1717
},
1818
"ava": {
1919
"failFast": true,
2020
"verbose": true
2121
},
2222
"devDependencies": {
23-
"ava": "^0.25.0",
24-
"codecov": "^3.1.0",
23+
"ava": "^1.3.1",
24+
"codecov": "^3.2.0",
2525
"cross-env": "^5.2.0",
26-
"eslint": "^5.5.0",
27-
"eslint-config-prettier": "^3.0.1",
28-
"eslint-plugin-prettier": "^2.6.2",
29-
"husky": "^0.14.3",
30-
"lint-staged": "^7.2.2",
31-
"moment": "^2.22.2",
32-
"mongoose": "^5.2.13",
33-
"nyc": "^13.0.1",
34-
"prettier": "^1.14.2",
35-
"remark-cli": "^5.0.0",
36-
"remark-preset-github": "^0.0.8",
37-
"xo": "^0.23.0"
26+
"eslint": "^5.15.3",
27+
"eslint-config-prettier": "^4.1.0",
28+
"eslint-plugin-prettier": "^3.0.1",
29+
"husky": "^1.3.1",
30+
"lint-staged": "^8.1.5",
31+
"moment": "^2.24.0",
32+
"mongoose": "^5.4.19",
33+
"nyc": "^13.3.0",
34+
"prettier": "^1.16.4",
35+
"remark-cli": "^6.0.1",
36+
"remark-preset-github": "^0.0.13",
37+
"xo": "^0.24.0"
3838
},
3939
"engines": {
4040
"node": ">=8.3"

test/test.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,7 @@ const slug = require('speakingurl');
55

66
const mongooseSlugPlugin = require('..');
77

8-
mongoose.connect(
9-
'mongodb://localhost/mongoose_slug_plugin',
10-
{
11-
useMongoClient: true
12-
}
13-
);
8+
mongoose.connect('mongodb://localhost/mongoose_slug_plugin');
149
mongoose.Promise = global.Promise;
1510

1611
const BlogPost = new mongoose.Schema({

0 commit comments

Comments
 (0)