powershell - 你能告诉我,如何在powershell中为日期开发参数化查询?
问题描述
Start-Process -FilePath "C:\Program Files\MongoDB\Tools\100\bin\mongoexport.exe" -ArgumentList ' --db=rndDB --collection=Messages --type=csv --fields Name,Message,Address ,Start_date,End_date -q "{"Start_date":{"$gte":{"$date":"2021-02-02T22:30:00.000Z"},"$lt":{"$date":" 2021-02-03T22:30:00.000Z"} } }" --out C:\Collection\Date_r2.csv'
解决方案
要扩展变量,必须将它们放在双引号中。我假设您需要其他双引号,因此您可以使用反引号将它们转义`:
Start-Process -FilePath "C:\Program Files\MongoDB\Tools\100\bin\mongoexport.exe" -ArgumentList (
' --db=rndDB' +
' --collection=Messages' +
' --type=csv' +
' --fields Name,Message,Address,Start_date,End_date' +
"-q `"{`"Start_date`":{`"$gte`":{`"$date`":`"2021-02-02T22:30:00.000Z`"},`"$lt`":{`"$date`":`"2021-02-03T22:30:00.000Z`"} } }" +
'--out C:\Collection\Date_r2.csv'
)
或者组合单引号字符串:
'-q "{"Start_date":{"'+$gte+'":{"'+$date+'":"2021-02-02T22:30:00.000Z"},"'+$lt+'":{"'+$date+'":"2021-02-03T22:30:00.000Z"} } }"' +
推荐阅读
- android - 从 .gradle 和 .idea 中删除所有内容是否安全?
- tampermonkey - Tampermonkey 的“存储”选项卡在哪里编辑存储内容?
- ruby - 尝试在 Ruby 中复制移动应用程序 POST 请求,出现 502 网关错误
- c++ - 正在跳过 cin 并且 cin.ignore 不起作用
- javascript - 使用 Javascript 更改类的 CSS 样式
- asp.net-core - 如何使用实体框架核心更新与普通 SQL 更新查询相同的多条记录列表?
- layout - 如何在颤动中制作自定义表格小部件?
- php - 当对数据库的调用位于包装器中时,PHP如何获取最后一个插入ID
- android - kotlin-runtime 和 kotlin-stdlib 之间的重复类
- python - ValueError:无法将字符串转换为浮点数:'(1/2)**576'