How can I insert Infinity field values into MongoDB using Mongoose

459 views Asked by At

In some situation, I need to store number such as Infinity and -Infinity into MongoDB using Mongoose. I have try in MongoDB shell, it works. But When I come to Mongoose, it fails. Any suggestion? Or this won't work at all?

In addition, it would be event better if I can insert NaN value into collections, is it possible?

ADD:

I simplify the code to as below:

var mongoose = require('mongoose'),
  Schema = mongoose.Schema;

mongoose.connect('mongodb://localhost/test');

var ResultSchema = new Schema({
  account: {
    type: Number,
    required: true,
    index: true,
    unique: true
  },
  profitLostRatio: Number,
});


var Result = mongoose.model('Result', ResultSchema);

var result = new Result({
  account: 18790314,
  profitLostRatio: Infinity
});

result.save(function(err, result) {
  if (err) {
    console.log(err);
  } else {
    console.log(JSON.stringify(result));
  }
});
0

There are 0 answers