52

I'm new to mongoDB and have a free Atlas account. But, I'm having issues with the mongo import.

system: windows

>mongo --version
MongoDB shell version v4.2.0
git version: a4b751dcf51dd249c5865812b390cfd1c0129c30
allocator: tcmalloc
modules: none
build environment:
    distmod: 2012plus
    distarch: x86_64
    target_arch: x86_64

mongoimport string:

mongoimport --host Cluster0-shard-0/cluster0-shard-00-00-MY.mongodb.net:27017,cluster0-shard-00-01-MY.mongodb.net:27017,cluster0-shard-00-02-MY.mongodb.net:27017 --ssl --username MYUSER --password MYPASS --authenticationDatabase admin --db db --collection coll --type json --file D:\downloads\records.json

But I keep getting this error:

2019-09-28T15:40:33.108-0600    WARNING: ignoring unsupported URI parameter 'replicaset'
2019-09-28T15:40:33.933-0600    connected to: mongodb://cluster...
2019-09-28T15:40:34.076-0600    Failed: cannot decode array into a D
2019-09-28T15:40:34.076-0600    0 document(s) imported successfully. 0 document(s) failed to import.
OhhhThatVarun
  • 3,981
  • 2
  • 26
  • 49
majortom84
  • 611
  • 1
  • 8
  • 16

1 Answers1

156

I just figured out. I had a JSON Array in the file, and for that, I had to append

--jsonArray

It is documented here

with the URL provided.

starball
  • 20,030
  • 7
  • 43
  • 238
daydreamer
  • 87,243
  • 191
  • 450
  • 722
  • 2
    latest document is here https://docs.mongodb.com/database-tools/mongoimport/ – Someone Special Aug 22 '20 at 09:21
  • Thank you so much for this. Helped immensely. My question is - what was your thought process in finding this solution? I'd like to learn how to solve things better on my own. Unfortunately, the error message "cannot decode array into a D" seemed entirely unhelpful to me. – GT. Feb 17 '22 at 11:04