Mongoose - lean() returning bson data

假装没事ソ 提交于 2019-12-08 05:52:23

问题


This query is not working as expecteed:

Model.find().select('_id').lean().exec(function(err, ids) {
    (...)
})

as far as I know lean() method should return the results of the query as js object., not mongodb bson.

edit:

actual result:

forEach(function(item, index, array) {
    console.log(item);
}

this:

_bsontype=ObjectID, 0=88, 1=198, 2=150, 3=109, 4=7, 5=81, 6=146, 7=44, 8=18, 9=94, 10=112, 11=159
_bsontype=ObjectID, 0=88, 1=198, 2=184, 3=185, 4=19, 5=120, 6=81, 7=12, 8=197, 9=73, 10=143, 11=217
_bsontype=ObjectID, 0=88, 1=198, 2=187, 3=53, 4=144, 5=27, 6=216, 7=20, 8=202, 9=80, 10=181, 11=183
_bsontype=ObjectID, 0=88, 1=198, 2=189, 3=10, 4=61, 5=115, 6=116, 7=28, 8=202, 9=233, 10=198, 11=106

expected results:

[{_id: "myid1"}, {_id: "myid2"}, {_id: "myid3"}, {_id: "myid4"}]

来源:https://stackoverflow.com/questions/42769613/mongoose-lean-returning-bson-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!