2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

csvをmongodbへupsertしたい人のためのコマンド

Last updated at Posted at 2020-10-09

mongodbへcsvをupsertしたい

そんな私みたいな人が居ると思いますので、コマンドを共有します。

環境説明

mondodbの環境は以下の通りです
-DB名:api
-コレクション名 : macList

コレクション

{
    "name":"   ",
    "mac" :"   "
}

※IDが勝手に入ります。

ファイル名
file.csv

コマンドは以下のとおりです

mongoimport --db=api--collection=macList --upsert --upsertFields=mac --type csv --file file.csv --headerline

各オプション解説
--db DB名
--collection コレクション名

--upsert アップサートでインポート
--upsertFields アップサートの際に既存にあるか確認するフィールド名

--type 入力ファイル形式
--file 入力ファイル名
--headerline ヘッダ行の無視

よろしくおねがいします。

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?