無法導入示例數據集(系統找不到指定文件) (Cannot import example dataset (the system cannot find the specified file))


問題描述

無法導入示例數據集(系統找不到指定文件) (Cannot import example dataset (the system cannot find the specified file))

我正在遵循 MongoDB 網站 這裡 上給出的示例,但我在嘗試導入示例數據時遇到了麻煩。

運行命令時

mongoimport ‑‑db test ‑‑collection restaurants ‑‑drop ‑‑file primer‑dataset.json

我收到錯誤:

失敗:打開Primer‑dataset.json: 系統找不到指定的文件

問題是,我不確定MongoDB希望這個文件在哪個目錄。我試著把它放在data/db ,但這沒有用。請注意,我只使用默認設置。

我知道這是一個微不足道的問題,我覺得問這個問題很愚蠢,但我在任何地方都找不到關於此的文檔。


參考解法

方法 1:

MongoDB expects the file to be in the directory from where you are running the command mongoimport.

If you place your file under data/db then set mongodb path as global environment variable and execute the command from data/db directory.

Additionally if you have security enabled for your mongodb then you need to execute command as below

mongoimport ‑‑username admin ‑‑password password ‑‑db test ‑‑collection restaurants ‑‑drop ‑‑file primer‑dataset.json

here admin is the user authorized to perform db operations for test database and restaurants is the collection name.

方法 2:

For Windows! Save file using notepad++ in .json format at MongoDB/bin where mongoimport command is present.

Simple notepad has trouble doing it.

方法 3:

It happened to me as well. The issue was that though the file was visible as restaurants.json actually the file was restaurants.json.json (since saved in JSON format). The issue was resolved after properly changing the name.

方法 4:

i have trouble like you, check you path to file, mongoimport.exe and your file may be stay in another folders.enter image description here

use mongoimport ‑d test1 ‑c restaraunts companies.json for import to mongodb.

方法 5:

Check the filename extension, and make sure it's a ".json" file; After this I successfully run the

mongoimport ‑‑db test ‑‑collection restaurants ‑‑drop ‑‑file [path\to\Json file]

command;

(by ericgrosserajadilipkollicode_loveAmjadh_IfthikarUladz KhaAnqi Bai)

參考文件

  1. Cannot import example dataset (the system cannot find the specified file) (CC BY‑SA 2.5/3.0/4.0)

#mongoDB






相關問題

將 (.net) BsonDocument 字符串轉換為 (java) DBObject (Converting (.net) BsonDocument string into a (java) DBObject)

Mongo 客戶端出錯 (Error with Mongo Client)

對列表進行排序並在 mongodb 中插入一個新列 (Sort the list and insert a new column in mongodb)

無法導入示例數據集(系統找不到指定文件) (Cannot import example dataset (the system cannot find the specified file))

mongodb c#更新嵌入文檔 (mongodb c# update embedded document)

查詢嵌入列表中的數組 (Querying for array in embedded list)

搜索條件的mongodb map reduce (mongodb map reduce for search criteria)

org.bson.codecs.configuration.CodecConfigurationException:找不到類 [Ljava.lang.String; 的編解碼器; (org.bson.codecs.configuration.CodecConfigurationException: Can't find a codec for class [Ljava.lang.String;)

在碼頭上部署 gwt Web 應用程序 (deploying gwt web application on jetty)

MongoMetaRecord MegaProtoUser 登錄時密碼未散列 (MongoMetaRecord MegaProtoUser Password not hashed when signing in)

將 mongo shell 連接到受限的 MongoDB Atlas 數據庫? (Connect mongo shell to restricted MongoDB Atlas Database?)

用於 $or 和 $and 場景的 $elemMatch 數組 (Arrays working $elemMatch for $or and $and scenarios)







留言討論