コレクションのすべてのクエリに対して基本的に射影規則を適用する方法はありますか? たとえば、 collectionがある場合、クエリが明示的に要求しない限り、ドキュメントに存在widget
するフィールドsecretAttribute
がデフォルトでクエリに返されないようにする方法はありますか? 投影パラメーターが明示的に拒否しない限り、自動的に投影されるprojection
方法とは反対の種類です。_id
たとえば、次のwidget
ドキュメントがあるとします。
{ _id: '51a4e3962dfff00105000009', name: 'foo', color: 'white', status: 'open', secretAttribute: 'bar' }
私が行うdb.widget.find({color: 'white'})
と、ドキュメントが返されますが、表示されませsecretAttribute
ん:
{ _id: '51a4e3962dfff00105000009', name: 'foo', color: 'white', status: 'open' }
secretAttribute
へのprojection
引数で明示的に要求する必要がありfind()
ます。
db.widget.find({color: 'white'}, {name:1, color:1, status: 1, secretAttribute: 1})
それを得るために。
ありがとう