Search code examples
mongodbcmdmongoimport

mongoimport fails to open file, "filename, directory name, or volume label syntax is incorrect"


I'm trying to import a json file into a MongoDB database. I'm trying every variation of mongoimport there are, but I keep getting the following error:

Failed: open 'C:\Users\<username>\Documents\data.json': The filename, directory name, or volume label syntax is incorrect.
imported 0 documents

I've used the following commands and they all give the same error code:

mongoimport --db submissions --collection tracks --file 'C:\Users\<username>\Documents\data.json' --jsonArray

mongoimport --db submissions --collection tracks --file 'C:\Users\<username>\Documents\data.json'

mongoimport -d submissions -c tracks --jsonArray 'C:\Users\<username>\Documents\data.json'

mongoimport --host localhost --db submissions --collection tracks --file 'C:\Users\<username>\Documents\data.json' --jsonArray

mongoimport --host localhost --db submissions --collection tracks --file 'C:\Users\<username>\Documents\data.json' --jsonArray

I'm trying to import the following one-line file:

{"items":[{"album":{"album_type":"album","artists":[{"external_urls":{"spotify":"https://open.spotify.com/artist/4iHNK0tOyZPYnBU7nGAgpQ"},"href":"https://api.spotify.com/v1/artists/4iHNK0tOyZPYnBU7nGAgpQ","id":"4iHNK0tOyZPYnBU7nGAgpQ","name":"Mariah Carey","type":"artist","uri":"spotify:artist:4iHNK0tOyZPYnBU7nGAgpQ"}],"available_markets":["AD","AE","AR","AT","AU","BE","BG","BH","BO","BR","CA","CH","CL","CO","CR","CY","CZ","DE","DK","DO","DZ","EC","EE","EG","ES","FI","FR","GB","GR","GT","HK","HN","HU","ID","IE","IL","IS","IT","JO","JP","KW","LB","LI","LT","LU","LV","MA","MC","MT","MX","MY","NI","NL","NO","NZ","OM","PA","PE","PH","PL","PS","PT","PY","QA","RO","SA","SE","SG","SK","SV","TH","TN","TR","TW","US","UY","VN","ZA"],"external_urls":{"spotify":"https://open.spotify.com/album/61ulfFSmmxMhc2wCdmdMkN"},"href":"https://api.spotify.com/v1/albums/61ulfFSmmxMhc2wCdmdMkN","id":"61ulfFSmmxMhc2wCdmdMkN","images":[{"height":640,"url":"https://i.scdn.co/image/e06f3ddadf59ee24504fc02bfe205945807a2437","width":640},{"height":300,"url":"https://i.scdn.co/image/46fb2752b5a9967f94c2cafd5f2903c89d6d8bf7","width":300},{"height":64,"url":"https://i.scdn.co/image/770180da03a8e23ac5ff7847496e9538cf73ce85","width":64}],"name":"Merry Christmas","release_date":"1994","release_date_precision":"year","total_tracks":10,"type":"album","uri":"spotify:album:61ulfFSmmxMhc2wCdmdMkN"},"artists":[{"external_urls":{"spotify":"https://open.spotify.com/artist/4iHNK0tOyZPYnBU7nGAgpQ"},"href":"https://api.spotify.com/v1/artists/4iHNK0tOyZPYnBU7nGAgpQ","id":"4iHNK0tOyZPYnBU7nGAgpQ","name":"Mariah Carey","type":"artist","uri":"spotify:artist:4iHNK0tOyZPYnBU7nGAgpQ"}],"available_markets":["AD","AE","AR","AT","AU","BE","BG","BH","BO","BR","CA","CH","CL","CO","CR","CY","CZ","DE","DK","DO","DZ","EC","EE","EG","ES","FI","FR","GB","GR","GT","HK","HN","HU","ID","IE","IL","IS","IT","JO","JP","KW","LB","LI","LT","LU","LV","MA","MC","MT","MX","MY","NI","NL","NO","NZ","OM","PA","PE","PH","PL","PS","PT","PY","QA","RO","SA","SE","SG","SK","SV","TH","TN","TR","TW","US","UY","VN","ZA"],"disc_number":1,"duration_ms":241106,"explicit":false,"external_ids":{"isrc":"USSM19400325"},"external_urls":{"spotify":"https://open.spotify.com/track/0bYg9bo50gSsH3LtXe2SQn"},"href":"https://api.spotify.com/v1/tracks/0bYg9bo50gSsH3LtXe2SQn","id":"0bYg9bo50gSsH3LtXe2SQn","is_local":false,"name":"All I Want for Christmas Is You","popularity":85,"preview_url":"https://p.scdn.co/mp3-preview/ab4f06069148ef8510d8681164479601d4617bed?cid=20eb7658092b44d8b5dfe668fcc6955e","track_number":2,"type":"track","uri":"spotify:track:0bYg9bo50gSsH3LtXe2SQn"}, {MORE ITEMS HERE} ]}

This is a Spotify API json response.

What am I doing wrong?


Solution

  • First it's not an array, so you do not need --jsonArray. And you're in a Windows terminal. Use double quotes " in the directory. Like that:

    mongoimport --db submissions --collection tracks --file "C:\Users\<username>\Documents\data.json"
    

    Let me know if this worked.