Start a new topic

How can I store 0 and false on the database?

When I try to store 0 or false on the database from business logic, they don't get stored -- I think they were stored till a few days ago tho...



For example:



doc.zeroNum = 0;

doc.zeroText = "0";

doc.falseBool = false;

doc.falseText = "false";

access.collection("Test").save(doc, function (err, result) { ... });



Will only store "zeroText" and "falseText" but not the others.



I could store everything as text and turn it into int / bool when I read it from the database... but it's not best.

Is there a way to store them as int and bool even when they're 0 and false?

ups I'm very sorry, my bad.

By checking again now I just found out couple of weeks ago I added a line on my custom "save" method to avoid saving null and undefined elements on the database.

But I didn't realize that rather than using a if ( variable != null ) I just used a if ( variable ) ...that rejects null and undefined, but also false and 0 -- I actually didn't know js was considering 0 as false, still learning :D



thanks for your response
How are you getting doc? The below code creates an entity and then retrieves it, and both false and 0 are saved and retrieved properly.



```

function onRequest(request, response, modules){

var falseTest = modules.collectionAccess.collection('falseTest');

var doc = {};

doc.a = false;

doc.b = 0;



falseTest.save(doc, function(err, result) {

if (err) {

response.error(err);

} else {

falseTest.find({}, function(err, result) {

if (err) {

return response.error(err);

}

response.body = result;

response.complete();

});

}

});



}

```
Login or Signup to post a comment