Skip to content

Tebancedoo/Practice-with-MongoDB

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

67 Commits
 
 
 
 
 
 

Repository files navigation

Practice-with-MongoDB

A short practice using MongoDB


Crar la base de datos "inventario"

use inventario

image


Insertar varios datos

db.inventario.insertMany([
{item: "journal", qty: 25, tags:["black","red"], dim_cm: [14,21]},
{item: "notebook", qty: 50, tags:["red","blank"], dim_cm: [14,21]},
{item: "paper", qty: 100, tags:["red","blank","pain"], dim_cm: [14,21]},
{item: "planner", qty: 75, tags:["black","red"], dim_cm: [22.85,30]},
{item: "postcard", qty: 45, tags:["blue"], dim_cm: [10,15.25]}
]);

image


Base de datos realizada

image


Consulta para buscar el dim_cm entre 10 y 15


db.inventario.find({ $and: [{"dim_cm": {$gt: 10}}, {"dim_cm": {$lt: 15}} ]});

image


Crear una base de datos llamada "tienda"


use tienda;

image


Creo la colecciòn "telefonos"


db.createCollection("telefonos");

image


Insertamos numeros de telefono

db.telefonos.insertMany([{"name": "AC3 phone", "brand": "ACME", "type": "phone", "price": 200, "rating": 3.8, "warranty_years": 1, "available": true},
{"name": "AC7 phone", "brand": "ACME", "type": "phone", "price": 320, "rating": 4, "warranty_years": 1, "available": false},
{"name": "AC3 series charger", "type": ["accesory","charger"], "price": 19, "rating": 2.8, "warranty_years": 0.25, "for": ["ac3", "ac7", "ac9"]},
{"name": "AC3 case green", "type": ["accesory","case"], "color": "green", "price": 12, "rating": 1, "warranty_years": 0 },
{"name": "phone extended warranty", "type": "warranty", "price": 38, "rating": 5, "warranty_years": 2, "for": ["ac3", "ac7", "ac9", "qp7", "qp8", "qp9"] },
{"name": "AC3 case black", "type": ["accesory","case"], "color": "black", "price": 12.5, "rating": 2, "warranty_years": 0.25, "available": false, "for": "ac3"},
{"name": "AC3 case red", "type": ["accesory","case"], "color": "red", "price": 12, "rating": 4, "warranty_years": 0.25, "available": true, "for": "ac3"},
{"name": "phone service basic plan", "type": "service", "monthly_price": 40, "rating": 3, "limits": {"voice": {"units": "minutes", "n": 400, "over_rate": 0.05}, "data": {"units": "gigabytes", "n": 20, "over_rate": 1 }, "sms": {"units": "text sent", "n": 100, "over_rate" :0.001 } }, "term_years" : 2},
{"name": "phone service core plan", "type": "service", "monthly_price": 60, "rating": 3, "limits": {"voice": {"units": "minutes", "n": 1000, "over_rate": 0.05}, "data": { "n": "unlimited", "over_rate": 0 }, "sms": {"n": "unlimited", "over_rate":0} },"term_years" : 1},
{"name": "phone service family plan", "type": "service", "monthly_price": 90, "rating": 4, "limits": {"voice": {"units": "minutes", "n": 1200, "over_rate": 0.05}, "data": { "n": "unlimited", "over_rate": 0 }, "sms": {"n": "unlimited", "over_rate": 0 }}, "sales_tax": true, "term_years": 2}]);

image


Consultas

Consultar elementos cuyo "type" sea "service"

db.telefonos.find({"type": "service"});

image

Consultar elementos cuyo "type" sea "service" y el precio mensual mayor de 50

db.telefonos.find({ $and: [{"type": "service"}, {"monthly_price": {$gt: 50}} ]});

image

Consultar elementos cuyo "type" sea "service " o el precio mensual mayor de 50

db.telefonos.find({ $or: [{"type": "service"}, {"monthly_price": {$gt: 50}} ]});

image


Practice-with-MongoDB part 2


Crear la base de datos "base1"

  use base1

image


Crear la collection "articulos"

db.createCollection("articulos");

image

Cargar 6 documentos

db.articulos.insertMany([
{ _id: 1, nombre: "impresora lenovo", rubro: "impresora",  precio: 150000, stock: 200},
{ _id: 2, nombre: "mouse tk", rubro: "mouse",  precio: 80000, stock: 50},
{ _id: 3, nombre: "impresora multifuncional", rubro: "impresora",  precio: 200000, stock: 3},
{ _id: 4, nombre: "pantalla lenovo", rubro: "pantalla",  precio: 100000, stock: 30},
{ _id: 5, nombre: "teclado hp", rubro: "teclado",  precio: 50000, stock: 55},
{ _id: 6, nombre: "audifonos gamer", rubro: "audifonos",  precio: 150000, stock: 90}
]);

image


Imprimir todos los documentos de la colección "articulos"

db.articulos.find();

image


Imprimir todos los documentos de la colección "articulos" que no son impresoras

db.articulos.find({ rubro: {$ne: "impresora"} });

image


Imprimir todos los artículos que pertenecen al rubro de "mouse"

db.articulos.find({"rubro": "mouse"});

image


Imprimir todos los artículos con un precio mayor o igual a 5000.

db.articulos.find({"precio":  { $gte: 5000} });

image


Imprimir todas las impresoras que tienen un precio mayor o igual a 3500.

db.articulos.find({ $and: [{"rubro": "impresora"}, {"precio": {$gte: 3500}} ]});

image


Imprimir todos los artículos cuyo stock se encuentra comprendido entre 0 y 4.

db.articulos.find( { stock: { $in: [ 0,1,2,3,4  ]} })

image

About

A short practice using MongoDB

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published