bash - 蒙戈 : drop collection using the terminal

标签 bash mongodb command-line-interface

我想将数据导入到几个集合中。我就是这样做的

$> mongoimport -d myDB -c myCollection --file file.json       

问题是这只有在集合为空时才有效,否则我会得到像

这样的错误
Mon Mar 31 10:45:52.696 E11000 duplicate key error index:.....

因为我想在 bash 脚本中执行此操作,所以我需要先清除/删除集合。我如何在 bash 脚本中执行此操作?

最佳答案

直接从手册页,使用 --drop选项:

--drop

Modifies the import process so that the target instance drops every collection before importing the collection from the input.

因此您可以删除您正在导入的集合并开始新的。

mongoimport -d myDB -c myCollection --drop --file file.json  

关于bash - 蒙戈 : drop collection using the terminal,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22757231/

相关文章:

regex - Bash 脚本 - 用于转储文件列表的正则表达式

bash - 试图了解Bash文件的设置/结构

amazon-web-services - AWS S3 cli在同一目录中的文件夹之间递归移动文件?

python - 寻找一个 GUI 应用程序来输入 linux 命令

bash - kafka-console-producer : command not found

regex - 如何使用 sed 忽略但保留 ANSI 转义码?

bash - 如何使用 bash 删除和替换终端中的最后一行?

node.js - 使用 Nodejs 脚本将 GB 数据从 MongoDB 迁移到 Cassandra 的最佳方法

MongoDB 聚合计算小时范围内的产品数量

javascript - 在 MongoDB 中搜索复数词形式时查找复数词和单数词