mongodb-queue
Advanced tools
Comparing version 2.1.0 to 2.2.0
@@ -72,8 +72,22 @@ /** | ||
var delay = opts.delay || self.delay | ||
var msg = { | ||
visible : delay ? nowPlusSecs(delay) : now(), | ||
payload : payload, | ||
var visible = delay ? nowPlusSecs(delay) : now() | ||
var msgs = [] | ||
if (payload instanceof Array) { | ||
payload.forEach(function(payload) { | ||
msgs.push({ | ||
visible : visible, | ||
payload : payload, | ||
}) | ||
}) | ||
} else { | ||
msgs.push({ | ||
visible : visible, | ||
payload : payload, | ||
}) | ||
} | ||
self.col.insertOne(msg, function(err, results) { | ||
self.col.insertMany(msgs, function(err, results) { | ||
if (err) return callback(err) | ||
if (payload instanceof Array) return callback(null, '' + results.insertedIds) | ||
callback(null, '' + results.ops[0]._id) | ||
@@ -80,0 +94,0 @@ }) |
{ | ||
"name": "mongodb-queue", | ||
"version": "2.1.0", | ||
"version": "2.2.0", | ||
"description": "Message queues which uses MongoDB.", | ||
@@ -5,0 +5,0 @@ "main": "mongodb-queue.js", |
@@ -5,3 +5,3 @@ # mongodb-queue # | ||
A really light-weight way to create queue with a nice API if you're already | ||
A really light-weight way to create queues with a nice API if you're already | ||
using MongoDB. | ||
@@ -250,2 +250,11 @@ | ||
Or add multiple messages: | ||
```js | ||
queue.add(['msg1', 'msg2', 'msg3'], function(err, ids) { | ||
// Messages with payloads 'msg1', 'msg2' & 'msg3' added. | ||
// All 'id's are returned as an array, useful for logging. | ||
}) | ||
``` | ||
You can delay individual messages from being visible by passing the `delay` option: | ||
@@ -268,2 +277,3 @@ | ||
// You can now process the message | ||
// IMPORTANT: The callback will not wait for an message if the queue is empty. The message will be undefined if the queue is empty. | ||
}) | ||
@@ -424,3 +434,3 @@ ``` | ||
* [NEW] Update MongoDB API from v1 to v2 (thanks https://ithub.com/hanwencheng) | ||
* [NEW] Update MongoDB API from v1 to v2 (thanks https://github.com/hanwencheng) | ||
@@ -427,0 +437,0 @@ ### 1.0.1 (2015-05-25) ### |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
72700
16
1472
521