Skip to content

Commit 8bfd20d

Browse files
committed
Checks the result of a find before returning it
1 parent 11894b5 commit 8bfd20d

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

lib/mongoHandler.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,11 @@ MongoStore.prototype.create = function(request, newResource, callback) {
301301
debug("insert", JSON.stringify(document));
302302
collection.insertOne(document, function(err) {
303303
if (err) return callback(MongoStore._unknownError(err));
304-
collection.findOne(document, { _id: 0 }, callback);
304+
collection.findOne(document, { _id: 0 }, function(findErr, result) {
305+
if (findErr) return callback(err);
306+
if (!result) return callback("Could not find document after insert");
307+
return callback(null, result);
308+
});
305309
});
306310
};
307311

0 commit comments

Comments
 (0)