mongodb将parameter passing给集合查找

我正在尝试将函数的parameter passing给mongodb集合查找。 喜欢这个:

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,不可以。

我build议你通过引用作为第一个参数apply ,或解开的参数,而不是:

 await db.collection('users').find(...arguments) 

澄清什么效果空作为第一个论据apply事宜…

 // 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)