Miembros:Edwin Chambi Montes Erik Adrian Espinoza Silez Jessica Hinojosa Coronel Practica de Mongodb

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 24

MIEMBROS:EDWIN CHAMBI MONTES

ERIK ADRIAN ESPINOZA SILEZ

JESSICA HINOJOSA CORONEL

PRACTICA DE MONGODB

//1

db.Personajes.distinct("Character Name");

//2

db.Personajes.aggregate([

$lookup: {

from: "Dialogos",

localField: "Character ID",

foreignField: "Character ID",

as: "Personajes"

},

$replaceRoot: {

newRoot: {

$mergeObjects: [

{ $arrayElemAt:[ "$Personajes", 0 ] }, "$$ROOT" ] } }

},

$project: {

"Character ID":1,

"Character Name":1,

"Dialogue ID":1,

"Chapter ID":1

},

{
$lookup: {

from: "Capitulos",

localField: "Chapter ID",

foreignField: "Chapter ID",

as: "PersonajesCapitulos"

},

$replaceRoot: {

newRoot: {

$mergeObjects: [

{ $arrayElemAt:[ "$PersonajesCapitulos", 0 ] }, "$$ROOT" ] } }

},

$project: {

"Character ID":1,

"Character Name":1,

"Dialogue ID":1,

"Chapter ID":1,

"Movie ID":1,

},

$lookup: {

from: "Characters",

localField: "Movie ID",

foreignField: "Movie ID",

as: "PersonajesPeliculas"

},

{
$replaceRoot: {

newRoot: {

$mergeObjects: [

{ $arrayElemAt:[ "$PersonajesPeliculas", 0 ] }, "$$ROOT" ] } }

},

$match: {

"Movie ID":4

]);

//3

db.Personajes.aggregate([

{ $lookup: {

from: "varitas",

localField: "varita",

foreignField: "_id",

as: "varita_info"

},

{ $project: {

_id: 1,

nombre: 1,

"varita.madera": { $arrayElemAt: [ "$varita_info.madera", 0 ] },

"varita.nucleo": { $arrayElemAt: [ "$varita_info.nucleo", 0 ] }

]);

//4

db.Personajes.aggregate([

{
$lookup: {

from: "Dialogos",

localField: "Character ID",

foreignField: "Character ID",

as: "Personajes"

},

$replaceRoot: {

newRoot: {

$mergeObjects: [

{ $arrayElemAt:[ "$Personajes", 0 ] }, "$$ROOT" ] } }

},

$project: {

"Character ID":1,

"Character Name":1,

"Dialogue ID":1,

"Chapter ID":1

},

$lookup: {

from: "Capitulos",

localField: "Chapter ID",

foreignField: "Chapter ID",

as: "PersonajesCapitulos"

},

$replaceRoot: {
newRoot: {

$mergeObjects: [

{ $arrayElemAt:[ "$PersonajesCapitulos", 0 ] }, "$$ROOT" ] } }

},

$project: {

"Character ID":1,

"Character Name":1,

"Dialogue ID":1,

"Chapter ID":1,

"Movie ID":1,

},

$lookup: {

from: "Peliculas",

localField: "Movie ID",

foreignField: "Movie ID",

as: "PersonajesPeliculas"

},

$replaceRoot: {

newRoot: {

$mergeObjects: [

{ $arrayElemAt:[ "$PersonajesPeliculas", 0 ] }, "$$ROOT" ] } }

},

$match: {

"Movie ID":{ $gt: 0, $lt: 5 }

}
}

]);

//5

db.Personajes.find({ "Peliculas": { "$elemMatch": { "$eq": "Movie ID" } } }).count();

//6

db.Capitulos.find({"Movie ID":7}).count();

//7

db.personajes.find(

{ "varita.nucleo": "dragón heartstring" },

{ nombre: 1 }

);

//8

db.Dialogos.aggregate([

$lookup: {

from: "Capitulos",

localField: "Chapter ID",

foreignField: "Chapter ID",

as: "DialogoPeliculas"

},

$unwind:"$DialogoPeliculas"

},

$match: {

"DialogoPeliculas.Movie ID":2

},

$count: 'NumDialogos'
}

]);

//9

db.Dialogos.find({ "Character ID": "HarryPotter" }).count();

//10

db.Personajes.find({"Patronus":""}).count();

//11

db.Personajes.find({ "varita.madera": "Cypress" }).count();

//12

db.Personajes.aggregate([

$match: {

"Wand (Core)":{$ne:""}

},

$group: {

_id: "$Wand (Core)",

count: { $sum: 1 }

},

$sort: {

"count": -1

]);

//13

db.Personajes.aggregate([

{ $group: { _id: "$especie", count: { $sum: 1 } } }

]);
//14

db.Personajes.aggregate([

$match: {

"House":{$ne:""}

},

$group: {

_id: "$House",

count: { $sum: 1 }

},

$sort: {

"count": -1

},

{ $limit : 1 }

]);

//15

db.Dialogos.aggregate([

{ $group: { _id: "$CharacterID", count: { $sum: 1 } } },

{ $sort: { count: -1 } },

{ $limit: 1 },

{ $lookup: { from: "Personajes", localField: "_id", foreignField: "CharacterID", as:


"Personajes" } },

{ $unwind: "$Personajes" },

{ $project: { nombre: "$Personajes.nombre" } }

]);

//16
db.Personajes.aggregate([

$match: {

"Patronus":{$ne:""}

},

$group: {

_id: "$Patronus",

count: { $sum: 1 }

},

$sort: {

"count": -1

},

{ $limit : 1 }

]);

//17

db.dialogos.aggregate([

$match: { personaje: "Harry Potter" }

},

$sample: { size: 5 }

},

$project: {

_id: 0,

dialogo: 1
}

]);

//18

db.Dialogos.aggregate([

$lookup: {

from: "Capitulos",

localField: "Chapter ID",

foreignField: "Chapter ID",

as: "DialCapitulos"

},

$replaceRoot: {

newRoot: {

$mergeObjects: [

{ $arrayElemAt:[ "$DialCapitulos", 0 ] }, "$$ROOT" ] } }

},

$group: {

_id: "$Movie ID",

count: { $sum: 1 }

},

$lookup: {

from: "Peliculas",

localField: "_id",
foreignField: "Movie ID",

as: "DialPeliculas"

},

$unwind:"$DialPeliculas"

},

$project: {

"_id":1,

"Movie Title":"$DialPeliculas.Movie Title",

"count":1

},

]);

//19

db.Dialogos.aggregate([

{ $group: { _id: "$CharacterID", count: { $sum: 1 } } },

{ $sort: { count: 1 } },

{ $limit: 1 },

{ $lookup: { from: "Peliculas", localField: "_id", foreignField: "CharacterID", as: "Peliculas" } },

{ $unwind: "$Peliculas" },

{ $project: { _id: 0, pelicula: "$pelicula.titulo", count: 1 } }

]);

//20

db.Personajes.aggregate([

$lookup: {

from: "Dialogos",

localField: "Character ID",

foreignField: "Character ID",


as: "Personajes"

},

$replaceRoot: {

newRoot: {

$mergeObjects: [

{ $arrayElemAt:[ "$Personajes", 0 ] }, "$$ROOT" ] } }

},

$project: {

"Character ID":1,

"Character Name":1,

"Dialogue ID":1,

"Chapter ID":1,

"Patronus":1

},

$lookup: {

from: "Capitulos",

localField: "Chapter ID",

foreignField: "Chapter ID",

as: "PersonajesCapitulos"

},

$replaceRoot: {

newRoot: {

$mergeObjects: [

{ $arrayElemAt:[ "$PersonajesCapitulos", 0 ] }, "$$ROOT" ] } }


},

$project: {

"Character ID":1,

"Character Name":1,

"Dialogue ID":1,

"Chapter ID":1,

"Movie ID":1,

"Patronus":1

},

$lookup: {

from: "Peliculas",

localField: "Movie ID",

foreignField: "Movie ID",

as: "PersonajesPeliculas"

},

$replaceRoot: {

newRoot: {

$mergeObjects: [

{ $arrayElemAt:[ "$PersonajesPeliculas", 0 ] }, "$$ROOT" ] } }

},

$project: {

"Character ID":1,

"Character Name":1,

"Patronus":1,

"Movie Title":1
}

},

]);

//21

db.dialogos.aggregate([

$match: { personaje: "Harry Potter" }

},

$lookup: {

from: "peliculas",

localField: "titulo",

foreignField: "titulo",

as: "pelicula_info"

},

$unwind: "$pelicula_info"

},

$group: {

_id: "$titulo",

num_dialogos: { $sum: "$num_dialogos" },

num_personajes: { $sum: 1 }

},

$project: {

_id: 0,

titulo: "$_id",
promedio_dialogos: { $divide: ["$num_dialogos", "$num_personajes"] }

]);

//22

db.Dialogos.aggregate([

$match: {

"Character ID":3

},

$lookup: {

from: "Capitulos",

localField: "Chapter ID",

foreignField: "Chapter ID",

as: "DialCapitulos"

},

$replaceRoot: {

newRoot: {

$mergeObjects: [

{ $arrayElemAt:[ "$DialCapitulos", 0 ] }, "$$ROOT" ] } }

},

$group: {

_id: "$Movie ID",

count: { $sum: 1 }
}

},

$lookup: {

from: "Peliculas",

localField: "_id",

foreignField: "Movie ID",

as: "DialPeliculas"

},

$unwind:"$DialPeliculas"

},

$project: {

"_id":1,

"Movie Title":"$DialPeliculas.Movie Title",

"count":1

},

$sort:{

"count":-1

]);

//23

db.peliculas.find(

{ titulo: "Harry Potter y la cámara secreta" },

{ actores: { $elemMatch: { nombre: "nombre_del_actor" } } }

);
db.peliculas.find(

{ titulo: "Harry Potter y la cámara secreta" },

{ actores: 1 }

);

//24

db.Capitulos.aggregate([

$group: {

_id: "$Movie ID",

PromedioCapitulos: { $avg: "$Chapter ID" }

},

]);

//25

db.Peliculas.aggregate([

$lookup: {

from: "actores",

localField: "actores",

foreignField: "_id",

as: "actores_info"

},

$unwind: "$actores_info"

},

$group: {

_id: "$_id",
titulo: { $first: "$titulo" },

num_actores: { $sum: 1 }

},

$project: {

_id: 0,

titulo: 1,

num_actores: 1

]);

//26

db.Capitulos.aggregate([

$group: {

_id: "$Movie ID",

"Capitulos": { $sum: 1 }

},

{ $sort:{

"Capitulos":-1

}},

$match: {

"Capitulos":{ $gt:30}

},
]);

//27

db.Peliculas.aggregate([

{ $group: { _id: "$_id", nombre: { $first: "$nombre" }, num_capitulos: { $sum:


"$num_capitulos" } } },

{ $project: { _id: 1, nombre: 1, num_capitulos: 1 } }

]);

//28

db.Peliculas.aggregate([

{ $group: { _id: "$nombre", num_capitulos: { $sum: "$num_capitulos" } } },

{ $sort: { num_capitulos: -1 } },

{ $limit: 1 },

{ $project: { _id: 0, nombre: "$_id" } }

]);

//29

db.personajes.aggregate([

$lookup: {

from: "actuaciones",

localField: "_id",

foreignField: "personaje_id",

as: "actuaciones"

},

$project: {

_id: 1,

nombre: 1,

num_peliculas: { $size: "$actuaciones.pelicula_id" }

}
}

]);

//30

db.Capitulos.aggregate([

$group: {

_id: "$Movie ID",

"Capitulos": { $sum: 1 }

},

{ $sort:{

"Capitulos":-1

}},

$limit : 1

},

$lookup: {

from: "Peliculas",

localField: "_id",

foreignField: "Movie ID",

as: "DialPeliculas"

},

$replaceRoot: {

newRoot: {

$mergeObjects: [

{ $arrayElemAt:[ "$DialPeliculas", 0 ] }, "$$ROOT" ] } }

},

{
$project: {

"Movie ID":1,

"Movie Title":2,

"Capitulos":3

]);

//31

db.dialogos.aggregate([

$project: {

_id: 0,

personaje: 1,

num_palabras: { $size: { $split: ["$dialogo", " "] } }

},

$sort: { num_palabras: -1 }

},

$limit: 1

]);

//32

db.Dialogos.aggregate([

$group: {

_id: "$Character ID",

"NumDialogos": { $sum: 1 }

}
},

$sort:{

"NumDialogos":-1

},

$limit:5

},

$lookup: {

from: "personajes2",

localField: "_id",

foreignField: "Character ID",

as: "DialogoPersonaje"

},

$replaceRoot: {

newRoot: {

$mergeObjects: [

{ $arrayElemAt:[ "$DialogoPersonaje", 0 ] }, "$$ROOT" ] } }

},

$project: {

"Character ID": 1,

"Character Name": 2,

"NumDialogos": 3,

}
]);

//33

db.Dialogos.aggregate([

$match: { dialogo: /harry potter/i }

},

$group: {

_id: "$titulo",

num_repeticiones: { $sum: { $regexMatch: { input: "$dialogo", regex: /harry potter/i } } }

},

$sort: { num_repeticiones: -1 }

]);

//34

db.Personajes.aggregate([

$group: {

_id: "$personaje",

totalDialogos: { $sum: 1 }

},

$match: {

totalDialogos: { $gte: 100, $lte: 200 }

},

{
$project: {

_id: 0,

personaje: "$_id",

totalDialogos: 1

]);

You might also like