Professional Documents
Culture Documents
Prueba Mongo
Prueba Mongo
928]
(c) Microsoft Corporation. Todos los derechos reservados.
C:\Program Files\MongoDB\Server\4.4\bin>mongo
MongoDB shell version v4.4.5
connecting to: mongodb://127.0.0.1:27017/?
compressors=disabled&gssapiServiceName=mongodb
Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed:
NetworkTimeout: Error connecting to 127.0.0.1:27017 :: caused by :: Socket
operation timed out :
connect@src/mongo/shell/mongo.js:374:17
@(connect):2:6
exception: connect failed
exiting with code 1
C:\Program Files\MongoDB\Server\4.4\bin>mongo
MongoDB shell version v4.4.5
connecting to: mongodb://127.0.0.1:27017/?
compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("8984068f-b61f-4144-ba6b-8d43ed2b77f6") }
MongoDB server version: 4.4.5
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
https://docs.mongodb.com/
Questions? Try the MongoDB Developer Community Forums
https://community.mongodb.com
---
The server generated these startup warnings when booting:
2021-05-10T07:14:29.326-05:00: Access control is not enabled for the
database. Read and write access to data and configuration is unrestricted
---
---
Enable MongoDB's free cloud-based monitoring service, which will then
receive and display
metrics about your deployment (disk utilization, CPU, operation statistics,
etc).
> db.estudiantes.deleteMany({})
{ "acknowledged" : true, "deletedCount" : 0 }
> db.estudiantes.insertOne({nombre:"pedro",promdeio:42})
{
"acknowledged" : true,
"insertedId" : ObjectId("60a4ff6279e7cc844ce91320")
}
> db.estudiantes.insertOne({nombre:"Maria",promdeio:42})
{
"acknowledged" : true,
"insertedId" : ObjectId("60a4ff6f79e7cc844ce91321")
}
> db.estudiantes.insertOne({nombre:"Juan",promdeio:43})
{
"acknowledged" : true,
"insertedId" : ObjectId("60a4ff7e79e7cc844ce91322")
}
> db.estudiantes.insertOne({nombre:"Maria",promdeio:43})
{
"acknowledged" : true,
"insertedId" : ObjectId("60a4ff9a79e7cc844ce91323")
}
> db.estudiantes.aggregate([{$match:{promedio:43}}])
> db.estudiantes.aggregate([{$match:{}},$group:{_id:"$promedio"},total{$sum:1}}}])
uncaught exception: SyntaxError: missing ] after element list :
@(shell):1:44
> db.estudiantes.aggregate([{$match:{}},$group:{_id:
{prom:"$promedio"},total{$sum:1}}}])
uncaught exception: SyntaxError: missing ] after element list :
@(shell):1:44
> db.estudiantes.aggregate([{$match:{}},$group:{_id:{prom:"$promedio"},total:
{$sum:1}}}])
uncaught exception: SyntaxError: missing ] after element list :
@(shell):1:44
> db.estudiantes.aggregate([{$match:{}},{$group:{_id:{prom:"$promedio"},total:
{$sum:1}}}])
{ "_id" : { "prom" : null }, "total" : 4 }
> db.estudiantes.find()
{ "_id" : ObjectId("60a4ff6279e7cc844ce91320"), "nombre" : "pedro", "promdeio" : 42
}
{ "_id" : ObjectId("60a4ff6f79e7cc844ce91321"), "nombre" : "Maria", "promdeio" : 42
}
{ "_id" : ObjectId("60a4ff7e79e7cc844ce91322"), "nombre" : "Juan", "promdeio" :
43 }
{ "_id" : ObjectId("60a4ff9a79e7cc844ce91323"), "nombre" : "Maria", "promdeio" : 43
}
> db.estudiantes.aggregate([{$match:{}},{$group:{_id:{prom:"$promdeio"},total:
{$sum:1}}}])
{ "_id" : { "prom" : 43 }, "total" : 2 }
{ "_id" : { "prom" : 42 }, "total" : 2 }
> db.estudiantes.aggregate([{$match:{}},{$group:{_id:{prom:"$promdeio"},total:
{$sum:2}}}])
{ "_id" : { "prom" : 42 }, "total" : 4 }
{ "_id" : { "prom" : 43 }, "total" : 4 }
> db.estudiantes.aggregate([{$match:{}},{$group:{_id:{prom:"$promdeio"},total:
{$sum:3}}}])
{ "_id" : { "prom" : 42 }, "total" : 6 }
{ "_id" : { "prom" : 43 }, "total" : 6 }
> db.estudiantes.aggregate([{$match:{}},{$group:{_id:
{prom:"$promdeio",nombre:"$nombre"},total:{$sum:3}}}])
{ "_id" : { "prom" : 42, "nombre" : "pedro" }, "total" : 3 }
{ "_id" : { "prom" : 42, "nombre" : "Maria" }, "total" : 3 }
{ "_id" : { "prom" : 43, "nombre" : "Maria" }, "total" : 3 }
{ "_id" : { "prom" : 43, "nombre" : "Juan" }, "total" : 3 }
> db.estudiantes.aggregate([{$match:{}},{$group:{_id:
{prom:"$promdeio",nombre:"$nombre"},total:{$sum:1}}}])
{ "_id" : { "prom" : 42, "nombre" : "pedro" }, "total" : 1 }
{ "_id" : { "prom" : 42, "nombre" : "Maria" }, "total" : 1 }
{ "_id" : { "prom" : 43, "nombre" : "Maria" }, "total" : 1 }
{ "_id" : { "prom" : 43, "nombre" : "Juan" }, "total" : 1 }
> db.estudiantes.insertOne({nombre:"Maria",promdeio:43})
{
"acknowledged" : true,
"insertedId" : ObjectId("60a5024279e7cc844ce91324")
}
> db.estudiantes.find()
{ "_id" : ObjectId("60a4ff6279e7cc844ce91320"), "nombre" : "pedro", "promdeio" : 42
}
{ "_id" : ObjectId("60a4ff6f79e7cc844ce91321"), "nombre" : "Maria", "promdeio" : 42
}
{ "_id" : ObjectId("60a4ff7e79e7cc844ce91322"), "nombre" : "Juan", "promdeio" :
43 }
{ "_id" : ObjectId("60a4ff9a79e7cc844ce91323"), "nombre" : "Maria", "promdeio" : 43
}
{ "_id" : ObjectId("60a5024279e7cc844ce91324"), "nombre" : "Maria", "promdeio" : 43
}
> db.estudiantes.aggregate([{$match:{}},{$group:{_id:
{prom:"$promdeio",nombre:"$nombre"},total:{$sum:1}}}])
{ "_id" : { "prom" : 42, "nombre" : "pedro" }, "total" : 1 }
{ "_id" : { "prom" : 42, "nombre" : "Maria" }, "total" : 1 }
{ "_id" : { "prom" : 43, "nombre" : "Juan" }, "total" : 1 }
{
> db.estudiantes.aggregate([{$match:{promdeio:43}},{$group:{_id:
{prom:"$promdeio",nombre:"$nombre"},total:{$sum:1}} ])
> db.estudiantes.aggregate([{$match:{promdeio:43}},{$group:{_id:
{prom:"$promdeio",nombre:"$nombre"},total:{$sum:1}}}
> db.estudiantes.aggregate([{$match:{promdeio:43}},{$group:{_id:
{prom:"$promdeio",nombre:"$nombre"},total:{$sum:1}}}]
> db.estudiantes.aggregate([{$match:{promdeio:43}},{$group:{_id:
{prom:"$promdeio",nombre:"$nombre"},total:{$sum:1}}}])
> db.estudiantes.aggregate([{$match:{promdeio:43}},{$group:{_id:
{nombre:"$nombre"},prom:{$avg:"$promdeio"},total:{$sum:1}}])
...
...
>
>
> db.estudiantes.aggregate([{$match:{promdeio:43}},{$group:{_id:
{prom:"$promdeio",nombre:"$nombre"},total:{$sum:1}}}])
{ "_id" : { "prom" : 43, "nombre" : "Juan" }, "total" : 1 }
{ "_id" : { "prom" : 43, "nombre" : "Maria" }, "total" : 2 }
> db.estudiantes.aggregate([{$match:{}},{$group:{_id:
{prom:"$promdeio",nombre:"$nombre"},total:{$sum:1}}}])
{ "_id" : { "prom" : 42, "nombre" : "pedro" }, "total" : 1 }
{ "_id" : { "prom" : 42, "nombre" : "Maria" }, "total" : 1 }
{ "_id" : { "prom" : 43, "nombre" : "Maria" }, "total" : 2 }
{ "_id" : { "prom" : 43, "nombre" : "Juan" }, "total" : 1 }
> db.estudiantes.aggregate([{$match:{promdeio:43}},{$group:{_id:
{prom:"$promdeio",nombre:"$nombre"},total:{$sum:1}}}])
{ "_id" : { "prom" : 43, "nombre" : "Maria" }, "total" : 2 }
{ "_id" : { "prom" : 43, "nombre" : "Juan" }, "total" : 1 }
> db.estudiantes.aggregate([{$match:{}},{$group:{_id:{nombre:"$nombre"},prom:
{$avg:"$promdeio"},total:{$sum:1}}])
...
...
> db.estudiantes.aggregate([{$match:{}},{$group:{_id:{nombre:"$nombre"},prom:
{$avg:"$promdeio"},total:{$sum:1}}}])
{ "_id" : { "nombre" : "Juan" }, "prom" : 43, "total" : 1 }
{ "_id" : { "nombre" : "Maria" }, "prom" : 42.666666666666664, "total" : 3 }
{ db.estudiantes.aggregate([{$match:{}},{$group:{_id:{nombre:"$nombre"},prom:
{$avg:"$promdeio"},total:{$sum:1}}},{$sort:{total:-1,nombre:1}}])
{ "_id" : { "nombre" : "Maria" }, "prom" : 42.666666666666664, "total" : 3 }:
{$avg:"$promdeio"},total:{$sum:1}}},{$sort:{total:-1,nombre:1}}])
{ "_id" : { "nombre" : "pedro" }, "prom" : 42, "total" : 1 }
{ "_id" : { "nombre" : "Juan" }, "prom" : 43, "total" : 1 }
> db.estudiantes.aggregate([{$match:{}},{$group:{_id:{nombre:"$nombre"},prom:
{$avg:"$promdeio"},total:{$sum:1}}},{$sort:{total:-1,nombre:1}}])
{ "_id" : { "nombre" : "Maria" }, "prom" : 42.666666666666664, "total" : 3 }
{ "_id" : { "nombre" : "Juan" }, "prom" : 43, "total" : 1 }
{ "_id" : { "nombre" : "pedro" }, "prom" : 42, "total" : 1 }
> db.estudiantes.drop()
true
> db.createCollection('estudiantes', {
...
... validator: {
...
... $jsonSchema: {
...
... bsonType: 'object',
...
... required: ['nombre', 'direccion', 'ciudad', 'carreras'],
...
... properties: {
...
... nombre: {
...
... bsonType: 'string',
...
... description: 'must be a string and is required'
...
... },
...
... direccion: {
...
... bsonType: 'string',
...
... description: 'must be a string and is required'
...
... },
...
... ciudad: {
...
... bsonType: 'objectId',
...
... description: 'must be an objectid and is required'
...
... },
...
... carreras: {
...
... bsonType: 'array',
...
... description: 'must be an array and is required',
...
... items: {
...
... bsonType: 'object',
...
... required: ['promedio','carrera' ],
...
... properties: {
...
... promedio: {
...
... bsonType: 'string',
...
... description: 'must be a string and is required'
...
... },
...
... carrera: {
...
... bsonType: 'objectId',
...
... description: 'must be an objectid and is required'
...
... }
...
... }
...
... }
...
... }
...
... }
...
... }
...
... }
...
... });
{ "ok" : 1 }
> db.estudiantes.insertOne("Juan","calle 45A # 13","Bogota",carreras:
[{promedio:43,carrera:"ingenieria"}])
uncaught exception: SyntaxError: missing ) after argument list :
@(shell):1:66
> db.estudiantes.insertOne("Juan","calle 45A # 13","Bogota",{carreras:
[{promedio:43,carrera:"ingenieria"}]})
uncaught exception: Error: argument passed to addIdIfNeeded is not an object :
DBCollection.prototype.addIdIfNeeded@src/mongo/shell/crud_api.js:31:15
DBCollection.prototype.insertOne@src/mongo/shell/crud_api.js:250:16
@(shell):1:1
> db.estudiantes.insertOne("Juan","calle 45A # 13","Bogota",
[{promedio:43,carrera:"ingenieria"}])
uncaught exception: Error: argument passed to addIdIfNeeded is not an object :
DBCollection.prototype.addIdIfNeeded@src/mongo/shell/crud_api.js:31:15
DBCollection.prototype.insertOne@src/mongo/shell/crud_api.js:250:16
@(shell):1:1
> db.estudiantes.insertOne("Juan","calle 45A # 13","Bogota",
{promedio:43,carrera:"ingenieria"})
uncaught exception: Error: argument passed to addIdIfNeeded is not an object :
DBCollection.prototype.addIdIfNeeded@src/mongo/shell/crud_api.js:31:15
DBCollection.prototype.insertOne@src/mongo/shell/crud_api.js:250:16
@(shell):1:1
> db.estudiantes.insertOne("Juan","calle 45A # 13","Bogota",carreras:
[{promedio:43,carrera:"ingenieria"}])
uncaught exception: SyntaxError: missing ) after argument list :
@(shell):1:66
> db.estudiantes.insertOne("Juan","calle 45A # 13","Bogota",carreras:
[{43,"ingenieria"}])
uncaught exception: SyntaxError: missing ) after argument list :
@(shell):1:66
> db.estudiantes.insertOne("Juan","calle 45A # 13","Bogota",[{43,"ingenieria"}])
uncaught exception: SyntaxError: missing : after property id :
@(shell):1:62
> db.estudiantes.insertOne("Juan","calle 45A # 13","Bogota",{carreras:
[{43,"ingenieria"}]})
uncaught exception: SyntaxError: missing : after property id :
@(shell):1:72
> db.estudiantes.insertOne({nombre:"Juan",direccion:"calle 45A #
13",ciudad:"Bogota",carreras:{43,"ingenieria"}})
uncaught exception: SyntaxError: missing : after property id :
@(shell):1:95
> db.estudiantes.insertOne({nombre:"Juan",direccion:"calle 45A #
13",ciudad:"Bogota",carreras:{promedio:43,carrera:"ingenieria"}})
WriteError({
"index" : 0,
"code" : 121,
"errmsg" : "Document failed validation",
"op" : {
"_id" : ObjectId("60a50ef579e7cc844ce91325"),
"nombre" : "Juan",
"direccion" : "calle 45A # 13",
"ciudad" : "Bogota",
"carreras" : {
"promedio" : 43,
"carrera" : "ingenieria"
}
}
}) :
WriteError({
"index" : 0,
"code" : 121,
"errmsg" : "Document failed validation",
"op" : {
"_id" : ObjectId("60a50ef579e7cc844ce91325"),
"nombre" : "Juan",
"direccion" : "calle 45A # 13",
"ciudad" : "Bogota",
"carreras" : {
"promedio" : 43,
"carrera" : "ingenieria"
}
}
})
WriteError@src/mongo/shell/bulk_api.js:458:48
mergeBatchResults@src/mongo/shell/bulk_api.js:855:49
executeBatch@src/mongo/shell/bulk_api.js:919:13
Bulk/this.execute@src/mongo/shell/bulk_api.js:1163:21
DBCollection.prototype.insertOne@src/mongo/shell/crud_api.js:264:9
@(shell):1:1
> db.estudiantes.find()
> db.estudiantes.insert({nombre:"Juan",direccion:"calle 45A #
13",ciudad:"Bogota",carreras:{promedio:43,carrera:"ingenieria"}})
WriteResult({
"nInserted" : 0,
"writeError" : {
"code" : 121,
"errmsg" : "Document failed validation"
}
})
> db.estudiantes.insertOne({nombre:"Juan",direccion:"calle 45A #
13",ciudad:"Bogota",carreras:{promedio:"4.3",carrera:"ingenieria"}})
WriteError({
"index" : 0,
"code" : 121,
"errmsg" : "Document failed validation",
"op" : {
"_id" : ObjectId("60a510c679e7cc844ce91327"),
"nombre" : "Juan",
"direccion" : "calle 45A # 13",
"ciudad" : "Bogota",
"carreras" : {
"promedio" : "4.3",
"carrera" : "ingenieria"
}
}
}) :
WriteError({
"index" : 0,
"code" : 121,
"errmsg" : "Document failed validation",
"op" : {
"_id" : ObjectId("60a510c679e7cc844ce91327"),
"nombre" : "Juan",
"direccion" : "calle 45A # 13",
"ciudad" : "Bogota",
"carreras" : {
"promedio" : "4.3",
"carrera" : "ingenieria"
}
}
})
WriteError@src/mongo/shell/bulk_api.js:458:48
mergeBatchResults@src/mongo/shell/bulk_api.js:855:49
executeBatch@src/mongo/shell/bulk_api.js:919:13
Bulk/this.execute@src/mongo/shell/bulk_api.js:1163:21
DBCollection.prototype.insertOne@src/mongo/shell/crud_api.js:264:9
@(shell):1:1
> db.productos.find()
> db.producto.find()
> db.carrera.insertOne(nombre:"ingenieria")
uncaught exception: SyntaxError: missing ) after argument list :
@(shell):1:27
> db.carrera.insertOne({nombre:"ingenieria"})
{
"acknowledged" : true,
"insertedId" : ObjectId("60a513ce79e7cc844ce91328")
}
> db.direcciones.insertOne({direccion:"calle 163 a#36"})
{
"acknowledged" : true,
"insertedId" : ObjectId("60a513fb79e7cc844ce91329")
}
> db.estudiantes.insertOne({nombre:"Juan",direccion:"calle 45A #
13",ciudad:"Bogota",carreras:{promedio:"4.3",carrera:""}})
WriteError({
"index" : 0,
"code" : 121,
"errmsg" : "Document failed validation",
"op" : {
"_id" : ObjectId("60a5141579e7cc844ce9132a"),
"nombre" : "Juan",
"direccion" : "calle 45A # 13",
"ciudad" : "Bogota",
"carreras" : {
"promedio" : "4.3",
"carrera" : ""
}
}
}) :
WriteError({
"index" : 0,
"code" : 121,
"errmsg" : "Document failed validation",
"op" : {
"_id" : ObjectId("60a5141579e7cc844ce9132a"),
"nombre" : "Juan",
"direccion" : "calle 45A # 13",
"ciudad" : "Bogota",
"carreras" : {
"promedio" : "4.3",
"carrera" : ""
}
}
})
WriteError@src/mongo/shell/bulk_api.js:458:48
mergeBatchResults@src/mongo/shell/bulk_api.js:855:49
executeBatch@src/mongo/shell/bulk_api.js:919:13
Bulk/this.execute@src/mongo/shell/bulk_api.js:1163:21
DBCollection.prototype.insertOne@src/mongo/shell/crud_api.js:264:9
@(shell):1:1
> db.estudiantes.insertOne({nombre:"Juan",direccion:"calle 45A #
13",ciudad:ObjectId("60a513fb79e7cc844ce91329"),carreras:
{promedio:"4.3",carrera:ObjectId("60a513ce79e7cc844ce91328")}})
WriteError({
"index" : 0,
"code" : 121,
"errmsg" : "Document failed validation",
"op" : {
"_id" : ObjectId("60a5145c79e7cc844ce9132b"),
"nombre" : "Juan",
"direccion" : "calle 45A # 13",
"ciudad" : ObjectId("60a513fb79e7cc844ce91329"),
"carreras" : {
"promedio" : "4.3",
"carrera" : ObjectId("60a513ce79e7cc844ce91328")
}
}
}) :
WriteError({
"index" : 0,
"code" : 121,
"errmsg" : "Document failed validation",
"op" : {
"_id" : ObjectId("60a5145c79e7cc844ce9132b"),
"nombre" : "Juan",
"direccion" : "calle 45A # 13",
"ciudad" : ObjectId("60a513fb79e7cc844ce91329"),
"carreras" : {
"promedio" : "4.3",
"carrera" : ObjectId("60a513ce79e7cc844ce91328")
}
}
})
WriteError@src/mongo/shell/bulk_api.js:458:48
mergeBatchResults@src/mongo/shell/bulk_api.js:855:49
executeBatch@src/mongo/shell/bulk_api.js:919:13
Bulk/this.execute@src/mongo/shell/bulk_api.js:1163:21
DBCollection.prototype.insertOne@src/mongo/shell/crud_api.js:264:9
@(shell):1:1
> db.estudiantes.insertOne({nombre:"Juan",direccion:"calle 45A #
13",ciudad:ObjectId("60a513fb79e7cc844ce91329"),carreras:
[{promedio:"4.3",carrera:ObjectId("60a513ce79e7cc844ce91328")}]})
{
"acknowledged" : true,
"insertedId" : ObjectId("60a5146b79e7cc844ce9132c")
}