我正在尝试使用日期范围字段查询集合中的数据,我的文档已实现正则表达式搜索,
我的查询如下,
db.getCollection('_event').find([{"name":{"$regex":"2017","$options":"i"}},{},{"date.start:{$gte":"2017-03-07T18:30:00.000Z"},{"date.end:{$lt":"2017-11-16T18:30:00.000Z"}])
和mongo抛出错误
错误:错误:{“waitedMS”:NumberLong(0),“ok”:0,“errmsg”: “无法解析:filter:[{name:{$ regex:\”2017 \“,$ options: \“i \”}},{},{date.start:{$ gte:\“2017-03-07T18:30:00.000Z \”},{ date.end:{$ lt:\“2017-11-16T18:30:00.000Z \”}]。 '过滤'字段必须 是BSON类型的对象。“,”“代码”:9}
任何帮助人员?
答案 0 :(得分:2)
find
方法的参数必须是JSON / BSON文档,而不是列表。尝试
db.getCollection('_event').find({
"name":{"$regex":"2017","$options":"i"},
"date.start":{"$gte":"2017-03-07T18:30:00.000Z"},
"date.end":{"$lt":"2017-11-16T18:30:00.000Z"}
})