在我的 mongo 数据库中,我有这种格式的数据
{ "_id" : { "$oid" : "53179b7f036457ea7fff00a7" }, "act" : "browserInfo", "creAt" : { "$date" : "2014-03-05T16:47:43.845-0500" }}
我正在尝试提出一个 shell 脚本,该脚本将使用以下脚本导出具有给定日期范围的条目(我将其命名为 csv_from_mongo_collection.sh)
#!/bin/bash
db_name=$1
collection=$2
output_file=$3
for i in "$@"
do
case $i in
--from=*)
from="${i#*=}"
shift
;;
--to=*)
to="${i#*=}"
shift
;;
esac
done
query="{creAt:{$gte:new Date($from),$lt:new Date($to)}}";
mongoexport --db "$db_name" --collection "$collection" --out "$output_file" --query "$query"
当我运行以下命令时,我看到该指定集合中的所有条目都已上传,而忽略了我设置的日期范围。
csv_from_mongo_collection.sh mydb analytics analytics_content.json --from=01/01/2013 --to=12/01/2013
有人可以帮助修复我的脚本/命令吗?谢谢