SHARE
TWEET

Untitled

a guest Jul 22nd, 2019 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Mongo Db runs based on (Key, Values)
  2.  
  3. For Mac
  4. Onde downloaded:
  5. in the terminal run these commands:
  6. from the root directory run
  7. `sudo mkdir data`
  8. `cd` in to the data directory
  9. `sudo mkdir db`
  10. Mongo requires these folder to run
  11.  
  12. the next step is to find the mongo Db file:
  13. /Users/$USER/Desktop/mongodb-osx-x86_64-4.0.10/bin/mongod
  14. go to the `bin` folder.
  15. run the mongod file then the mongo file, these will launch a local instants of mongo db
  16. the other will open the mongo db CLI.
  17.  
  18. *** If you encounter a 100 error, this means that the DB does not have write access to the data/db directory
  19. its a simple fix of giving it access
  20.  
  21. `sudo chmod -R go+w data/db/`
  22.  
  23. now rerun the commands
  24.  
  25. Commands:
  26.  
  27. once mongo is running in a terminal
  28. you can run `cls` which clears the terminal window.
  29.  
  30. To build or access an existing database
  31. `use someDb`
  32.  
  33. If the DB doesn't exist Mongo will create it and switch you to that db
  34.  
  35. all mongo commands run inside of the DB will require
  36. `db` to be run then the database name `db.someDoc`
  37.  
  38. `db.some.insertOne()` format the input like a JSON you can keep recreating the same thing.
  39.  
  40. `db.some.insertOne({name:"Joe", age"23", userName:"JoeyJoe"})`
  41. *It is easier to do this in a IDE, but make sure whenb you copy in back over you have vertical quotation marks
  42. * other wise you will get a syntax error
  43.  
  44. `db.some.find()` this will return all of the entries in the db
  45. `db.som.find({name: "Joe"})` if you pass in an arguement it will return only those Documents whoes name contains "Joe"
  46. The find is CASE SENSENTIVE if one entry is "Joe" and the other is "joe" only "Joe" will be returned
  47.  
  48. if you want to update a document you can simply do it by
  49. db.some.update({_id: "1"},{$set:{email: "joe@email.com}})
  50.  
  51. you can also update and $unset it
  52. db.people.update({_id: "1"},{$unset:{age: "does not matter"}})
  53.  
  54. count `db.some.find().count`
  55.  
  56. Kotlin and mongoDb:
  57. connecting to a mongoDb you will need to add the dependcies to Maven or Gradle
  58. rebuild the DM
  59. create a mongo driver file in your project
  60.  
  61. `val mongoClient = MongoClient("127.0.0.0", 27017)`
  62. you will want to connect a new instance of the mongo client, pass in the arguements ("Host string", port Int)
  63. these can be found on the mongod in the terminal.
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top