Skip to content

Commit 03f57e3

Browse files
committed
Merge pull request holidayextras#24 from holidayextras/resultCheck
Checks the result of a find before returning it
2 parents 11894b5 + 84b55f9 commit 03f57e3

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
- 2016-04-07 - v1.2.2
2+
- 2016-04-07 - Error handling when creating a document
13
- 2016-02-17 - v1.2.1
24
- 2016-02-17 - Improved filtering by non-string attributes
35
- 2016-01-21 - v1.2.0

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jsonapi-store-mongodb",
3-
"version": "1.2.1",
3+
"version": "1.2.2",
44
"description": "MongoDB data store for jsonapi-server.",
55
"main": "lib/mongoHandler.js",
66
"repository": {

0 commit comments

Comments
 (0)