私はこのコードを持っています:
var regex={"$regex":req.query.query,"$options":req.query.options }
db.collection('coders', function(err, collection) {
collection.find(
{"name":regex}
).toArray(function(err, items) {
res.send(items);
});
});
期待どおりにうまく機能します。「名前」の代わりに任意のフィールドを使用できるようにしたいので、これをテストしました:
var regex={"$regex":req.query.query,"$options":req.query.options }
var field="\"notName\""
db.collection('coders', function(err, collection) {
collection.find(
{field:regex}
).toArray(function(err, items) {
res.send(items);
});
});
これは機能しません。問題は何ですか?変数を使用して collection.find() を呼び出す正しい方法は何ですか?