Mongoimport将数据类型应用于所有字段的字符串
当我们导入CSV文件数据MongoDimport
自动选择每个字段的数据类型。
是否可以将数据类型应用于所有字段的字符串? - columnShavetypes 可以帮助定义字段类型。但是我不想定义每个字段并手动键入。
这是我的Schell脚本:
cd <path to direcotry of csv files>
$files = Get-ChildItem .
foreach ($f in $files) {
if ($f -Like "*.csv") {
mongoimport -d mydb -c mycollection --type csv --file $f --headerline
}
}
感谢您的帮助!
When we import CSV file data mongodimport
automatically choose data type for each field.
Is it possible to apply the data type as the string for all fields? the --columnsHaveTypes can help to define the field type. But I don't want to define each field and type manually.
Here is my schell script:
cd <path to direcotry of csv files>
$files = Get-ChildItem .
foreach ($f in $files) {
if ($f -Like "*.csv") {
mongoimport -d mydb -c mycollection --type csv --file $f --headerline
}
}
Appreciate your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我需要将单个字段设置为字符串,但其余的我希望MongoDB自动定义类型。解决方案是在使用MongoImport之前使用标题线并修改CSV的标题行,这是将一个字段(url_key)作为字符串作为字符串的示例代码,但其余自动定义:
I needed to set a single field as a string but the rest I wanted mongodb to automatically define the type. The solution was to use headerline and modify the header row of the CSV before using mongoimport, here is example code for keeping one field (url_key) as a string but the rest auto-defined: