I'm trying to use floats as keys in a mongodb database since I have to store the respective amount of each money value (e.g. 0.01: 10). But when I try saving the data via mongoose (node server using express) it only saves the data with normal (String) keys in the db.
This is my schema:
var ProtokollSchema = new Schema({
"date": String,
"0.01": {type: Number, default: 0},
"0.02": {type: Number, default: 0},
"0.05": {type: Number, default: 0},
"0.10": {type: Number, default: 0},
"0.20": {type: Number, default: 0},
"0.50": {type: Number, default: 0},
"1.00": {type: Number, default: 0},
"2.00": {type: Number, default: 0},
...
});
This is the express function setting the data:
.post(function(req, res) {
var protokoll = new ProtokollSchema();
protokoll["date"] = req.body["date"];
protokoll["0.01"] = req.body.data["0.01"];
protokoll["0.02"] = req.body.data["0.02"];
protokoll["0.05"] = req.body.data["0.05"];
protokoll["0.10"] = req.body.data["0.10"];
protokoll["0.20"] = req.body.data["0.20"];
protokoll["0.50"] = req.body.data["0.50"];
protokoll["1.00"] = req.body.data["1.00"];
protokoll["2.00"] = req.body.data["2.00"];
...
protokoll.save(function(err) {
if (err) res.json(err);
res.json({ message: "Comment successfully added!"});
});
})
Is there a solution or is it just not possible to do?