mskw
mskw

Reputation: 10358

Mongodb save create new collection

For some strange reason, I cannot create a new collection. Here is what I did:

use newdb
switched to db newdb
db.getCollectionNames()
[ ]
db.teams.save({country:"Ukraine",GroupName:"D"})
WriteResult({
    "nInserted" : 0,
    "writeError" : {
        "code" : 18825,
        "errmsg" : "couldn't create file /data/db/newdb.ns"
    }
})

I could save to any other DB or collections that I've already created however.

Any ideas?

Upvotes: 0

Views: 173

Answers (1)

Mihir Bhende
Mihir Bhende

Reputation: 9045

Check if you have created folder /data/db and it has relevant permissions. Basically mongodb is trying to save all metadata files in /data/db folder. Either /data/db its not present or its not having permissions to write on.

You can do following in terminal to check the error more specifically :

tail -50 /var/log/mongodb/mongodb.log

Check the owner of the file :

sudo chown -r mongodb:mongodb /data/db

Check permissions of the folder :

sudo chmod 775 -r /data/db

Upvotes: 1

Related Questions