- Mac
- Windows
- Linux
Create a folder in your User/Home directory. This way the folder permissions are to you the user and mongodb has read/write permissions. Without those permissions it can't create data.
mkdir -p ~/data/db
e.g. (windows can be a different path)
mongod -p -dbpath ~/data/db/
mongo shell
we are going to use the test db
use test
this switches to the test database
show collections
We will now use some of the simple methods that allow you to make changes to the collections
mongodb collection methods
db.createCollection('people')
when you run 'show collections' now you will see the 'people' collection
NOTE: your are passing in a 'javascript' object, key value pairs into the insert() function using the {} braces
db.people.insert({firstname: 'YOURNAME', lastname: 'YOURLASTNAME'})
db.foods.find()
This returns the ObjectId for each record, replace ObjectId in the next step
db.foods.findOneAndDelete(ObjectId("5761fc4b639f77271a098f51"))
This will return the removed value in the console for a validation of what was removed.