関数の引数を mongodb コレクションの find に渡そうとしています。このような:
async find() {
try {
return await db.collection('users').find.apply(null, arguments);
} catch(err) {
console.error(err);
}
}
返す
TypeError: Cannot read property 's' of null at Collection.find (/localpath/node_modules/mongodb/lib/collection.js:282:22)
走れる
await db.collection('users').find()
そしてカーソルが返されます。したがって、接続とコレクションは適切に設定されています。
ここで得られないものは何ですか?
適用する最初の引数は null です。null にすることはできません。
参照を最初の引数として に渡すapply
か、代わりに引数をラップ解除することをお勧めします。
await db.collection('users').find(...arguments)
apply
問題の最初の引数として null がどのような影響を与えるかを明確にしてください...
// will log "hello"
({foo:function(){console.log(this.bar)}, bar:'hello'}).foo()
// will log undefined
({foo:function(){console.log(this.bar)}, bar:'hello'}).foo.apply(null)
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加