mongodbmongoimportmongoexport

Collection name error while importing Json to MongoDB


As I was importing a new json file to my mongodb collection I've accidentally use just one '-' instead of 2. Eg.:

mongoimport --host=127.0.0.1 --db=dataBaseName -collection=people --file=importFile.json

I believe that due to the lack of the second '-', now I'm stuck with the following results when I type show collections:

people
ollection=people

I can't access, drop or interact with the second one. Apart from droping the database and starting over, is there a way around this issue?


Solution

  • You can rename the collection like:

    > use YourDatabase
    // Might wanna drop people collection first
    > db.getCollection("ollection=people").renameCollection("people")
    

    Hope This helps!