es6 spread operator - mongoose result copy

后端 未结 1 729
暗喜
暗喜 2020-12-29 03:43

I\'m developping an express js API with mongo DB and mongoose.

I would like to create an object in Javascript es6 composed of few variables and the result of a mongo

相关标签:
1条回答
  • 2020-12-29 04:31

    You can use the Mongoose Document.toObject() method. It will return the underlying plain JavaScript object fetched from the database.

    const newObject = {...result.toObject(), toto: "toto"};
    

    You can read more about the .toObject() method here.

    0 讨论(0)
提交回复
热议问题