Monday, 13 March 2017

Mongoose - lean() returning bson data

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"}]



via UnicodeUnicorn

No comments:

Post a Comment