What is the correct type to use for an ObjectId field across mongoose and GraphQL?

后端 未结 3 451
清酒与你
清酒与你 2021-01-13 22:34

Following this tutorial, I have a mongoose model: (I\'m using the term \"Account\" instead of \"Todo\", but it\'s the same thing)

const Account = mongoose.m         


        
3条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-13 22:58

    I used ID and it works fine! cause of your problem is not id's type! it's becuase you provide it with wrong value: ObjectID('actuall id')

    In order to fix this issue, call toJson function for each fetched data, or simply add a virtual id like this:

    YourSchema.virtual('id').get(function() {
        return this.toJSON()._id
    }
    

提交回复
热议问题