Skip to content

Commit

Permalink
Merge pull request #11 from reedsy/remove-undefined-prop
Browse files Browse the repository at this point in the history
🐛 Remove undefined props
  • Loading branch information
dawidreedsy authored Jan 2, 2024
2 parents 9a5c893 + 772580d commit bf640e1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion mongodb-queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export default class Queue<T = any> {
});
}

const results = await this.col.insertMany(msgs);
const results = await this.col.insertMany(msgs, {ignoreUndefined: true});
if (payload instanceof Array) return '' + results.insertedIds;
return '' + results.insertedIds[0];
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@reedsy/mongodb-queue",
"version": "5.1.0",
"version": "6.0.0",
"description": "Message queues which uses MongoDB.",
"main": "mongodb-queue.js",
"scripts": {
Expand Down
11 changes: 11 additions & 0 deletions test/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@ setup().then(({client, db}) => {
t.end();
});

test('remove undefined properties', async function(t) {
const queue = new MongoDbQueue(db, 'default');
const id = await queue.add({text: 'Hello, World!', undefinedProp: undefined});
t.ok(id, 'Received an id for this message');

const msg = await queue.get();
t.ok(msg.id, 'Got a msg.id');
t.equal('undefinedProp' in msg.payload, false, 'Payload has undefinedProp and it should be removed');
t.end();
});

test('client.close()', function(t) {
t.pass('client.close()');
client.close();
Expand Down

0 comments on commit bf640e1

Please sign in to comment.