Say you define a Mongoose schema like so
aSchema = new Schema
count: Number
text: String
A = mongoose.model "A", aSchema
db = mongoose.connect "mongodb://localhost/test"
a = new A
a.count = 99
a.text = "foo"
a.save (err) ->
A.findById a, (err, a) ->
console.log typeof a.text, typeof a.count #prints string, object
Fields of type String behave as expected. But Number fields come back as objects, which means they need to be typecast before being used in comparisons etc.
Why do fields of type Number need casting but not fields of type String?
From one of the authors: https://github.com/LearnBoost/mongoose/issues/338#issuecomment-1092330
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