Skip to content

Commit 84496e2

Browse files
committed
💥 Promisify and add mongodb@5 support
[`mongodb@5`][1] drops support for callbacks, which breaks this library, which is all written with callbacks. This is a **BREAKING** change which drops callback support from this library as well, and fully embraces promises through `async`/`await` syntax in both the library code and test code. This allows us to support both `mongodb@4` and `mongodb@5`. [1]: https://github.com/mongodb/node-mongodb-native/releases/tag/v5.0.0
1 parent 9c7e02f commit 84496e2

File tree

15 files changed

+694
-1481
lines changed

15 files changed

+694
-1481
lines changed

‎README.md‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const client = new mongodb.MongoClient(url, { useNewUrlParser: true })
2626

2727
client.connect(err => {
2828
const db = client.db('test')
29-
const queue = mongoDbQueue(db, 'my-queue')
29+
const queue = new MongoDbQueue(db, 'my-queue')
3030

3131
// ...
3232

@@ -102,9 +102,9 @@ passed in:
102102
var mongoDbQueue = require('mongodb-queue')
103103
104104
// an instance of a queue
105-
var queue1 = mongoDbQueue(db, 'a-queue')
105+
var queue1 = new MongoDbQueue(db, 'a-queue')
106106
// another queue which uses the same collection as above
107-
var queue2 = mongoDbQueue(db, 'a-queue')
107+
var queue2 = new MongoDbQueue(db, 'a-queue')
108108
```
109109

110110
Using `queue1` and `queue2` here won't interfere with each other and will play along nicely, but that's not
@@ -116,7 +116,7 @@ it's not something you should do.
116116
To pass in options for the queue:
117117

118118
```
119-
var resizeQueue = mongoDbQueue(db, 'resize-queue', { visibility : 30, delay : 15 })
119+
var resizeQueue = new MongoDbQueue(db, 'resize-queue', { visibility : 30, delay : 15 })
120120
```
121121

122122
This example shows a queue with a message visibility of 30s and a delay to each message of 15s.
@@ -131,8 +131,8 @@ Each queue you create will be it's own collection.
131131
e.g.
132132

133133
```
134-
var resizeImageQueue = mongoDbQueue(db, 'resize-image-queue')
135-
var notifyOwnerQueue = mongoDbQueue(db, 'notify-owner-queue')
134+
var resizeImageQueue = new MongoDbQueue(db, 'resize-image-queue')
135+
var notifyOwnerQueue = new MongoDbQueue(db, 'notify-owner-queue')
136136
```
137137

138138
This will create two collections in MongoDB called `resize-image-queue` and `notify-owner-queue`.
@@ -149,7 +149,7 @@ You may set this visibility window on a per queue basis. For example, to set the
149149
visibility to 15 seconds:
150150

151151
```
152-
var queue = mongoDbQueue(db, 'queue', { visibility : 15 })
152+
var queue = new MongoDbQueue(db, 'queue', { visibility : 15 })
153153
```
154154

155155
All messages in this queue now have a visibility window of 15s, instead of the
@@ -167,7 +167,7 @@ retrieval 10s after being added.
167167
To delay all messages by 10 seconds, try this:
168168

169169
```
170-
var queue = mongoDbQueue(db, 'queue', { delay : 10 })
170+
var queue = new MongoDbQueue(db, 'queue', { delay : 10 })
171171
```
172172

173173
This is now the default for every message added to the queue.
@@ -182,8 +182,8 @@ automatically see problem messages.
182182
Pass in a queue (that you created) onto which these messages will be pushed:
183183

184184
```js
185-
var deadQueue = mongoDbQueue(db, 'dead-queue')
186-
var queue = mongoDbQueue(db, 'queue', { deadQueue : deadQueue })
185+
var deadQueue = new MongoDbQueue(db, 'dead-queue')
186+
var queue = new MongoDbQueue(db, 'queue', { deadQueue : deadQueue })
187187
```
188188

189189
If you pop a message off the `queue` over `maxRetries` times and still have not acked it,
@@ -246,7 +246,7 @@ If you want to opt in to using the newer `returnDocument`, set the `returnDocume
246246
to `true`:
247247

248248
```
249-
var queue = mongoDbQueue(db, 'queue', { returnDocument : true })
249+
var queue = new MongoDbQueue(db, 'queue', { returnDocument : true })
250250
```
251251

252252
## Operations ##

0 commit comments

Comments
 (0)