开发者

Mongoose and field types - Number returns object, String returns string?

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 et开发者_StackOverflowc.

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜