【MongoDB】findでレスポンスデータのフィルタが効かない

エラー内容

findでレスポンスデータのフィルタが効かない

原因

MongoDBのバージョンが変わって仕様が変わった

修正内容

1
2
3
4
# 修正前
coll.find({ a: 42 }, { someField: 1 });
# 修正後
coll.find({ a: 42 }).project({ someField: 1 });

参考

https://stackoverflow.com/questions/48451300/projection-not-working-with-db-collection-find-in-mongo

以上

【MongoDB】findでレスポンスデータのフィルタが効かない

https://reon777.com/2019/12/24/mongo-projection-not-working/

Author

reon777

Posted on

2019-12-24

Updated on

2026-06-30

Your browser is out-of-date!

Update your browser to view this website correctly.&npsb;Update my browser now

×