MongoDB

Mongo VS SQL commands, my article on Mongo: https://github.com/lakesare/LocomotiveCMS-tutorial

11 flashcards · Programming Languages · by lakesare

  1. What's the difference between mongo and mongod?

    mongod: that's how you start mongo server mongo: that's how you access shell for that server. They should be at the same port. mongod is the "Mongo Daemon" it's basically the host process for the database. When you start mongod you're basically saying "start the MongoDB process and run it in the background". mongod has several default parameters, such as storing data in /data/db and running on port 27017.mongo is the command-line shell that connects to a specific instance of mongod. When you ru…

  2. How to create a database from mongo shell?

    use DATABASE_NAME The command will create a new database if it doesn't exist, otherwise it will return the existing database.

  3. Name commands to dump and restore mongo db.

    mongodump mongorestore , run from the terminal. Because mongodump and mongorestore operate by interacting with a running mongod instance, they can impact the performance of your running database. Not only do the tools create traffic for a running database instance, they also force the database to read all data through memory. Links: https://docs.mongodb.com/manual/tutorial/backup-and-restore-tools

  4. Where will the contents of mongodump --uri "mongodb://..." be saved? What command line argument controls it?

    By default, mongodump saves output files in a directory named /dump in the current working directory (LOCALLY). You can change it via --out argument. Links: docs

  5. Imagine we have my_dump in the current working directory. What syntax to use to restore it?

    mongorestore --port <port number of a running mongod> my_dump

  6. What will this do: db.inventory.find( { qty: { $ne: 20 } } )

    Select all documents in inventory collection where the qty field value does not equal 20, including those documents that do not contain the qty field.

  7. How to delete all documents from a unicorns collection with name 'evelyn'?

    db.unicorns.remove({name: 'evelyn'}) #will delete records with name: 'evelyn'

  8. What's a document in MongoDB?

    A row.

  9. What are embedded documents?

    When you embed related data in a single document. These schema are generally known as “denormalized” models. What embedded association basically is, is a document embedded in another document. You could think it's a bad style from relation database point of view, but it's actually a preferred way of organizing a document-oriented db. The reasoning behind it is as follows:- MongoDB provides no transactions, and no join support, so it is impossible to ensure that the database is kept in a consist…

  10. How to update unicorn with some id with new fields?

    db.unicorns.update( { _id: 100 }, { $set: { quantity: 500, details: { model: "14Q3", make: "xyz" }, tags: [ "coats", "outerwear", "clothing" ] } } )

  11. What does that mean: db.unicorns.find( { amount_of_legs: { $gt: 20 } } )

    Find all unicorns with amount of legs greater than 20.