I like to initially save data to a new mongodb in my Meteor App. The collection is a available an the following code works. But decision.visble is created as String, though I would like to have it as boolean. How do I pass this information? Is this done via the insert?
Client
var decision = {};
decision.visble = 'false';
Meteor.call('addDecision',decision);
Sever
'addDecision':function(decision){
return Decision.insert(decision);
}
EDIT
Just found a kind of answer for me:
The type seems to be take automatically. So when I leave out the quotes and pass only false instead of 'false' I get a boolean type instead of a sting.
But there must be a smarter procedure. Here is a List of BSON types
which seem to be used in an $type operator. So finally remains the question:
How do I correctly define the datatypes I want to store in a collection?
You assigned the visible field using the string syntax "false" so its JS type will be String.
You simply need to make the field into a Boolean using the plain false keyword :
decision.visible = false;
EDIT :
How do I correctly define the datatypes I want to store in a collection?
You could use something like simple-schema : https://github.com/aldeed/meteor-simple-schema
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With