Skip to content

Commit

Permalink
🐛 Don't send null or undefined values to MongoDB when creating a record
Browse files Browse the repository at this point in the history
  • Loading branch information
skerit committed Sep 10, 2024
1 parent 46fd4d2 commit d248e43
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## 1.4.0-alpha.6 (WIP)

* Don't flatten objects when updating records, it causes too many issues
* Don't send null or undefined values to MongoDB when creating a record

## 1.4.0-alpha.5 (2024-08-16)

Expand Down
14 changes: 13 additions & 1 deletion lib/app/datasource/mongo_datasource.js
Original file line number Diff line number Diff line change
Expand Up @@ -491,9 +491,21 @@ Mongo.setMethod(function _create(context) {
this.collection(model.table),
collection => {

const data = context.getConvertedData();
const converted_data = context.getConvertedData();
const pledge = new Swift();

let data = {};

for (let key in converted_data) {
let val = converted_data[key];

if (val == null) {
continue;
}

data[key] = val;
}

Pledge.done(collection.insertOne(data, {w: 1, fullResult: true}), function afterInsert(err, result) {

// Clear the cache
Expand Down

0 comments on commit d248e43

Please sign in to comment.