How to get array of json objects rather than mongoose documents

前端 未结 2 1007
暖寄归人
暖寄归人 2021-02-01 17:46

When I do find operation like the follows:

Collection.find({name: \'Erik\'}, function (err, docs) {
   // do momething
});

\'docs\' variable is

2条回答
  •  故里飘歌
    2021-02-01 18:51

    If you're using Mongoose 3.x you can use the lean query option to do this:

    Collection.find({name: 'Erik'}).lean().exec(function (err, docs) {
        // docs are plain javascript objects instead of model instances
    });
    

提交回复
热议问题