Giter VIP home page Giter VIP logo

mongodb_test's Introduction

CI logo

Welcome NicolaLampis,

This is the Code Institute student template for Gitpod. We have preinstalled all of the tools you need to get started. You can safely delete this README.md file, or change it for your own project. Please do read it at least once, though! It contains some important information about Gitpod and the extensions we use.

Gitpod Reminders

To run a frontend (HTML, CSS, Javascript only) application in Gitpod, in the terminal, type:

python3 -m http.server

A blue button should appear to click: Make Public,

Another blue button should appear to click: Open Browser.

To run a backend Python file, type python3 app.py, if your Python file is named app.py of course.

A blue button should appear to click: Make Public,

Another blue button should appear to click: Open Browser.

In Gitpod you have superuser security privileges by default. Therefore you do not need to use the sudo (superuser do) command in the bash terminal in any of the lessons.

Gitpod

  • Connect to Mongo CLI on Gitpod
  • navigate to your MongoDB Clusters Sandbox
  • click "Connect" button
  • select "Connect with the mongo shell"
  • select "I do not have the mongo shell installed"
  • choose option: "Run your connection string in your command line"
  • mongo "mongodb+srv://<CLUSTER-NAME>.mongodb.net/<DBname>" --username <USERNAME>
    • replace all <angle-bracket> keys with your own data
  • enter password *(will not echo ******** on screen)

Clear screen in Mongo Shell:

  • cls

Show all database collections:

  • show collections

Assign collection to variable 'coll':

  • coll = db.collection_name

Insert data to collection:

coll.insert({
    first: "john",
    last: "lennon",
    dob: "09/10/1940",
    gender: "m",
    hair_color: "brown",
    occupation: "beatle",
    nationality: "british"
});
coll.insert({
    first: "eve",
    last: "ryan",
    dob: "19/09/1992",
    gender: "f",
    hair_color: "pink",
    occupation: "developer",
    nationality: "irish"
});
coll.insert({
    first: "martha",
    last: "fenton",
    dob: "15/05/1974",
    gender: "f",
    hair_color: "brown",
    occupation: "manager",
    nationality: "irish"
});
coll.insert({
    first: "neil",
    last: "hanslem",
    dob: "14/07/1983",
    gender: "m",
    hair_color: "blonde",
    occupation: "actor",
    nationality: "british"
});
coll.insert({
    first: "rocky",
    last: "persolm",
    dob: "19/12/1994",
    gender: "f",
    hair_color: "black",
    occupation: "activist",
    nationality: "american"
});

Find all documents in collection:

  • coll.find();

Find all documents with gender == "f":

  • coll.find({gender: "f"});

Find all documents with gender == "f" AND nationality == "british":

  • coll.find({gender: "f", nationality: "british"});

Find all documents with gender == "f" AND nationality == "american" OR "irish":

  • coll.find({gender: "f", $or: [{nationality: "american"}, {nationality: "irish"}]});

Find all documents with gender == "f" AND nationality == "american" OR "irish", then sort by nationality (ascending):

  • coll.find({gender: "f", $or: [{nationality: "american"}, {nationality: "irish"}]}).sort({nationality: 1});

Find all documents with gender == "f" AND nationality == "american" OR "irish", then sort by nationality (descending):

  • coll.find({gender: "f", $or: [{nationality: "american"}, {nationality: "irish"}]}).sort({nationality: -1});

Update the first matching record with nationality == "irish" to have hair_color == "blue":

  • coll.update({nationality: "irish"}, {$set: {hair_color: "blue"}});

Update all matching records with nationality == "irish" to have hair_color == "purple":

  • coll.update({nationality: "irish"}, {$set: {hair_color: "purple"}},{multi:true});

Delete a record matching: First: "kate", Last: "bush":

  • coll.remove({first: "kate", last: "bush"});

Delete all records from the collection:

  • coll.remove();

mongodb_test's People

Contributors

nicolalampis avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.