我正在尝试将json文件导入MongoDB数据库。我正在尝试 mongoimport 的所有变体,但我不断收到以下错误:
Failed: open 'C:\Users\<username>\Documents\data.json': The filename, directory name, or volume label syntax is incorrect.
imported 0 documents
我使用了以下命令,它们都给出相同的错误代码:
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
我正在尝试导入以下单行文件:
{"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} ]}
这是一个Spotify API json响应。
我在做什么错了?
答案 0 :(得分:0)
首先,它不是数组,因此不需要--jsonArray
。而且您在Windows终端中。在目录中使用双引号"
。像这样:
mongoimport --db submissions --collection tracks --file "C:\Users\<username>\Documents\data.json"
让我知道这是否可行。