[go: up one dir, main page]

0% found this document useful (0 votes)
43 views14 pages

Command Prompt - Mongo

Download as txt, pdf, or txt
Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1/ 14

Microsoft Windows [Version 10.0.22631.

4037]
(c) Microsoft Corporation. All rights reserved.

C:\Users\akram>mongo
MongoDB shell version v5.0.28
connecting to: mongodb://127.0.0.1:27017/?
compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("47267134-f9d8-4d01-8719-81e9cbcee797") }
MongoDB server version: 5.0.28
================
Warning: the "mongo" shell has been superseded by "mongosh",
which delivers improved usability and compatibility.The "mongo" shell has been
deprecated and will be removed in
an upcoming release.
For installation instructions, see
https://docs.mongodb.com/mongodb-shell/install/
================
---
The server generated these startup warnings when booting:
2024-09-19T16:52:26.031+05:30: Access control is not enabled for the
database. Read and write access to data and configuration is unrestricted
---
> use database
switched to db database
> db.student.find()
{ "_id" : 1, "name" : "Akram", "cgpa" : 8.03, "age" : 20, "branch" : "cse" }
{ "_id" : 2, "name" : "yash", "cgpa" : 7.7, "age" : 20, "branch" : "cse" }
{ "_id" : 3, "name" : "harsha", "cgpa" : 8.1, "age" : 30, "branch" : "CAI" }
{ "_id" : 4, "name" : "bhanu", "age" : 21, "cgpa" : 7, "branch" : "csd" }
> Adb.student.aggregate($matchA^C
bye

C:\Users\akram>

C:\Users\akram>> db.student.find()
The syntax of the command is incorrect.

C:\Users\akram>{ "_id" : 1, "name" : "Akram", "cgpa" : 8.03, "age" : 20, "branch" :


"cse" }
'{' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\akram>{ "_id" : 2, "name" : "yash", "cgpa" : 7.7, "age" : 20, "branch" :


"cse" }
'{' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\akram>{ "_id" : 3, "name" : "harsha", "cgpa" : 8.1, "age" : 30, "branch" :


"CAI" }
'{' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\akram>{ "_id" : 4, "name" : "bhanu", "age" : 21, "cgpa" : 7, "branch" :


"csd" }
'{' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\akram>> Adb.student.aggregate($matchA
The syntax of the command is incorrect.
C:\Users\akram>
C:\Users\akram>
C:\Users\akram>
C:\Users\akram>
C:\Users\akram>> db.student.find()
The syntax of the command is incorrect.
C:\Users\akram>{ "_id" : 1, "name" : "Akram", "cgpa" : 8.03, "age" : 20, "branch" :
"cse" }
'{' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\akram>{ "_id" : 2, "name" : "yash", "cgpa" : 7.7, "age" : 20, "branch" :


"cse" }
'{' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\akram>{ "_id" : 3, "name" : "harsha", "cgpa" : 8.1, "age" : 30, "branch" :


"CAI" }
'{' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\akram>{ "_id" : 4, "name" : "bhanu", "age" : 21, "cgpa" : 7, "branch" :


"csd" }
'{' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\akram>> Adb.student.aggregate($matchA
The syntax of the command is incorrect.

C:\Users\akram>
C:\Users\akram>
C:\Users\akram>e syntax of the command is incorrect.
'e' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\akram>C:\Users\akram>{ "_id" : 1, "name" : "Akram", "cgpa" : 8.03, "age" :


20, "branch" : "cse" }
'C:\Users\akram' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\akram>'{' is not recognized as an internal or external command,


''{'' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\akram>operable program or batch file.


'operable' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\akram>
C:\Users\akram>C:\Users\akram>{ "_id" : 2, "name" : "yash", "cgpa" : 7.7, "age" :
20, "branch" : "cse" }
'C:\Users\akram' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\akram>mongo
MongoDB shell version v5.0.28
connecting to: mongodb://127.0.0.1:27017/?
compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("55931698-927d-49c8-886b-d131aaf9a130") }
MongoDB server version: 5.0.28
================
Warning: the "mongo" shell has been superseded by "mongosh",
which delivers improved usability and compatibility.The "mongo" shell has been
deprecated and will be removed in
an upcoming release.
For installation instructions, see
https://docs.mongodb.com/mongodb-shell/install/
================
---
The server generated these startup warnings when booting:
2024-09-19T16:52:26.031+05:30: Access control is not enabled for the
database. Read and write access to data and configuration is unrestricted
---
> db.student.find()
> use database
switched to db database
> db.student.find()
{ "_id" : 1, "name" : "Akram", "cgpa" : 8.03, "age" : 20, "branch" : "cse" }
{ "_id" : 2, "name" : "yash", "cgpa" : 7.7, "age" : 20, "branch" : "cse" }
{ "_id" : 3, "name" : "harsha", "cgpa" : 8.1, "age" : 30, "branch" : "CAI" }
{ "_id" : 4, "name" : "bhanu", "age" : 21, "cgpa" : 7, "branch" : "csd" }
> db.createcollection("AAmazon")
uncaught exception: TypeError: db.createcollection is not a function :
@(shell):1:1
> db.createcollection("AAmazon");
uncaught exception: TypeError: db.createcollection is not a function :
@(shell):1:1
> db.createcollection("AAmazon")
uncaught exception: TypeError: db.createcollection is not a function :
@(shell):1:1
> db.createCollection("AAmazon")
{ "ok" : 1 }
> use ecommercedb
switched to db ecommercedb
> db.createCollection("Mobiles")
{ "ok" : 1 }
> db.createCollection("TV")
{ "ok" : 1 }
> db.createCollection("Headphones")
{ "ok" : 1 }
> db.createCollection("Laptops")
{ "ok" : 1 }
> db.createCollection("Watches")
{ "ok" : 1 }
> db.Mobiles.insertMany([
... { "Name": "iPhone 13", "Brand": "Apple", "Cost": 799, "Color": "Black",
"Rating": 4.8 },
... { "Name": "Galaxy S21", "Brand": "Samsung", "Cost": 749, "Color": "Silver",
"Rating": 4.5 },
... { "Name": "OnePlus 9", "Brand": "OnePlus", "Cost": 699, "Color": "Blue",
"Rating": 4.3 },
... { "Name": "Pixel 6", "Brand": "Google", "Cost": 599, "Color": "White",
"Rating": 4.6 },
... { "Name": "Redmi Note 10", "Brand": "Xiaomi", "Cost": 199, "Color":
"Green", "Rating": 4.2 },
... { "Name": "Moto G Power", "Brand": "Motorola", "Cost": 249, "Color":
"Black", "Rating": 4.1 },
... { "Name": "iPhone SE", "Brand": "Apple", "Cost": 399, "Color": "Red",
"Rating": 4.4 },
... { "Name": "Galaxy A52", "Brand": "Samsung", "Cost": 349, "Color": "Blue",
"Rating": 4.2 },
... { "Name": "OnePlus Nord", "Brand": "OnePlus", "Cost": 399, "Color": "Gray",
"Rating": 4.3 },
... { "Name": "Pixel 5a", "Brand": "Google", "Cost": 449, "Color": "Black",
"Rating": 4.5 }
... ])
{
"acknowledged" : true,
"insertedIds" : [
ObjectId("66ed2d9f46f537c4a934a80a"),
ObjectId("66ed2d9f46f537c4a934a80b"),
ObjectId("66ed2d9f46f537c4a934a80c"),
ObjectId("66ed2d9f46f537c4a934a80d"),
ObjectId("66ed2d9f46f537c4a934a80e"),
ObjectId("66ed2d9f46f537c4a934a80f"),
ObjectId("66ed2d9f46f537c4a934a810"),
ObjectId("66ed2d9f46f537c4a934a811"),
ObjectId("66ed2d9f46f537c4a934a812"),
ObjectId("66ed2d9f46f537c4a934a813")
]
}
> db.TV.insertMany([
... { "Name": "Bravia 55", "Brand": "Sony", "Cost": 999, "Color": "Black",
"Rating": 4.7 },
... { "Name": "OLED C1", "Brand": "LG", "Cost": 1299, "Color": "Black",
"Rating": 4.8 },
... { "Name": "QLED Q60", "Brand": "Samsung", "Cost": 899, "Color": "Silver",
"Rating": 4.6 },
... { "Name": "4K UHD 65", "Brand": "TCL", "Cost": 699, "Color": "Black",
"Rating": 4.5 },
... { "Name": "X900H", "Brand": "Sony", "Cost": 1199, "Color": "Black",
"Rating": 4.7 },
... { "Name": "Q70T", "Brand": "Samsung", "Cost": 999, "Color": "Gray",
"Rating": 4.6 },
... { "Name": "CX OLED", "Brand": "LG", "Cost": 1399, "Color": "Black",
"Rating": 4.9 },
... { "Name": "V-Series 50", "Brand": "Vizio", "Cost": 499, "Color": "Black",
"Rating": 4.3 },
... { "Name": "H8G", "Brand": "Hisense", "Cost": 549, "Color": "Gray",
"Rating": 4.2 },
... { "Name": "U7G", "Brand": "Hisense", "Cost": 799, "Color": "Silver",
"Rating": 4.4 }
... ])
{
"acknowledged" : true,
"insertedIds" : [
ObjectId("66ed2dcf46f537c4a934a814"),
ObjectId("66ed2dcf46f537c4a934a815"),
ObjectId("66ed2dcf46f537c4a934a816"),
ObjectId("66ed2dcf46f537c4a934a817"),
ObjectId("66ed2dcf46f537c4a934a818"),
ObjectId("66ed2dcf46f537c4a934a819"),
ObjectId("66ed2dcf46f537c4a934a81a"),
ObjectId("66ed2dcf46f537c4a934a81b"),
ObjectId("66ed2dcf46f537c4a934a81c"),
ObjectId("66ed2dcf46f537c4a934a81d")
]
}
> db.Headphones.insertMany([
... { "Name": "AirPods Pro", "Brand": "Apple", "Cost": 249, "Color": "White",
"Rating": 4.7 },
... { "Name": "QC35 II", "Brand": "Bose", "Cost": 299, "Color": "Silver",
"Rating": 4.8 },
... { "Name": "WH-1000XM4", "Brand": "Sony", "Cost": 349, "Color": "Black",
"Rating": 4.9 },
... { "Name": "Galaxy Buds", "Brand": "Samsung", "Cost": 149, "Color": "White",
"Rating": 4.5 },
... { "Name": "Beats Studio3", "Brand": "Beats", "Cost": 349, "Color": "Red",
"Rating": 4.6 },
... { "Name": "QuietComfort Earbuds", "Brand": "Bose", "Cost": 279, "Color":
"Black", "Rating": 4.7 },
... { "Name": "Soundcore Q30", "Brand": "Anker", "Cost": 99, "Color": "Blue",
"Rating": 4.4 },
... { "Name": "Elite 85h", "Brand": "Jabra", "Cost": 249, "Color": "Black",
"Rating": 4.6 },
... { "Name": "Momentum 3", "Brand": "Sennheiser", "Cost": 399, "Color":
"Gray", "Rating": 4.8 },
... { "Name": "Pixel Buds", "Brand": "Google", "Cost": 179, "Color": "White",
"Rating": 4.5 }
... ])
{
"acknowledged" : true,
"insertedIds" : [
ObjectId("66ed2de946f537c4a934a81e"),
ObjectId("66ed2de946f537c4a934a81f"),
ObjectId("66ed2de946f537c4a934a820"),
ObjectId("66ed2de946f537c4a934a821"),
ObjectId("66ed2de946f537c4a934a822"),
ObjectId("66ed2de946f537c4a934a823"),
ObjectId("66ed2de946f537c4a934a824"),
ObjectId("66ed2de946f537c4a934a825"),
ObjectId("66ed2de946f537c4a934a826"),
ObjectId("66ed2de946f537c4a934a827")
]
}
> db.Laptops.insertMany([
... { "Name": "MacBook Pro", "Brand": "Apple", "Cost": 1999, "Color": "Silver",
"Rating": 4.9 },
... { "Name": "XPS 13", "Brand": "Dell", "Cost": 1399, "Color": "Black",
"Rating": 4.8 },
... { "Name": "ThinkPad X1", "Brand": "Lenovo", "Cost": 1599, "Color": "Black",
"Rating": 4.7 },
... { "Name": "Surface Laptop 4", "Brand": "Microsoft", "Cost": 1299, "Color":
"Platinum", "Rating": 4.6 },
... { "Name": "Yoga Slim 7i", "Brand": "Lenovo", "Cost": 999, "Color": "Gray",
"Rating": 4.5 },
... { "Name": "Spectre x360", "Brand": "HP", "Cost": 1399, "Color": "Blue",
"Rating": 4.7 },
... { "Name": "ROG Zephyrus G14", "Brand": "Asus", "Cost": 1449, "Color":
"White", "Rating": 4.8 },
... { "Name": "Swift 3", "Brand": "Acer", "Cost": 799, "Color": "Silver",
"Rating": 4.4 },
... { "Name": "Blade 15", "Brand": "Razer", "Cost": 2499, "Color": "Black",
"Rating": 4.9 },
... { "Name": "Pavilion 15", "Brand": "HP", "Cost": 699, "Color": "Gold",
"Rating": 4.2 }
... ])
{
"acknowledged" : true,
"insertedIds" : [
ObjectId("66ed2df846f537c4a934a828"),
ObjectId("66ed2df846f537c4a934a829"),
ObjectId("66ed2df846f537c4a934a82a"),
ObjectId("66ed2df846f537c4a934a82b"),
ObjectId("66ed2df846f537c4a934a82c"),
ObjectId("66ed2df846f537c4a934a82d"),
ObjectId("66ed2df846f537c4a934a82e"),
ObjectId("66ed2df846f537c4a934a82f"),
ObjectId("66ed2df846f537c4a934a830"),
ObjectId("66ed2df846f537c4a934a831")
]
}
> db.Watches.insertMany([
... { "Name": "Apple Watch Series 7", "Brand": "Apple", "Cost": 399, "Color":
"Black", "Rating": 4.8 },
... { "Name": "Galaxy Watch 4", "Brand": "Samsung", "Cost": 249, "Color":
"Silver", "Rating": 4.6 },
... { "Name": "Fitbit Sense", "Brand": "Fitbit", "Cost": 299, "Color": "Pink",
"Rating": 4.5 },
... { "Name": "Garmin Fenix 6", "Brand": "Garmin", "Cost": 599, "Color":
"Gray", "Rating": 4.7 },
... { "Name": "Amazfit GTR 3", "Brand": "Amazfit", "Cost": 179, "Color":
"Black", "Rating": 4.4 },
... { "Name": "TicWatch Pro 3", "Brand": "Mobvoi", "Cost": 299, "Color":
"Black", "Rating": 4.3 },
... { "Name": "Suunto 7", "Brand": "Suunto", "Cost": 499, "Color": "Orange",
"Rating": 4.2 },
... { "Name": "Fossil Gen 5", "Brand": "Fossil", "Cost": 279, "Color": "Brown",
"Rating": 4.5 },
... {
...
...
> db.Mobiles.find().pretty()
{
"_id" : ObjectId("66ed2d9f46f537c4a934a80a"),
"Name" : "iPhone 13",
"Brand" : "Apple",
"Cost" : 799,
"Color" : "Black",
"Rating" : 4.8
}
{
"_id" : ObjectId("66ed2d9f46f537c4a934a80b"),
"Name" : "Galaxy S21",
"Brand" : "Samsung",
"Cost" : 749,
"Color" : "Silver",
"Rating" : 4.5
}
{
"_id" : ObjectId("66ed2d9f46f537c4a934a80c"),
"Name" : "OnePlus 9",
"Brand" : "OnePlus",
"Cost" : 699,
"Color" : "Blue",
"Rating" : 4.3
}
{
"_id" : ObjectId("66ed2d9f46f537c4a934a80d"),
"Name" : "Pixel 6",
"Brand" : "Google",
"Cost" : 599,
"Color" : "White",
"Rating" : 4.6
}
{
"_id" : ObjectId("66ed2d9f46f537c4a934a80e"),
"Name" : "Redmi Note 10",
"Brand" : "Xiaomi",
"Cost" : 199,
"Color" : "Green",
"Rating" : 4.2
}
{
"_id" : ObjectId("66ed2d9f46f537c4a934a80f"),
"Name" : "Moto G Power",
"Brand" : "Motorola",
"Cost" : 249,
"Color" : "Black",
"Rating" : 4.1
}
{
"_id" : ObjectId("66ed2d9f46f537c4a934a810"),
"Name" : "iPhone SE",
"Brand" : "Apple",
"Cost" : 399,
"Color" : "Red",
"Rating" : 4.4
}
{
"_id" : ObjectId("66ed2d9f46f537c4a934a811"),
"Name" : "Galaxy A52",
"Brand" : "Samsung",
"Cost" : 349,
"Color" : "Blue",
"Rating" : 4.2
}
{
"_id" : ObjectId("66ed2d9f46f537c4a934a812"),
"Name" : "OnePlus Nord",
"Brand" : "OnePlus",
"Cost" : 399,
"Color" : "Gray",
"Rating" : 4.3
}
{
"_id" : ObjectId("66ed2d9f46f537c4a934a813"),
"Name" : "Pixel 5a",
"Brand" : "Google",
"Cost" : 449,
"Color" : "Black",
"Rating" : 4.5
}
> db.Tv.find().pretty()
> db.TV.find().pretty()
{
"_id" : ObjectId("66ed2dcf46f537c4a934a814"),
"Name" : "Bravia 55",
"Brand" : "Sony",
"Cost" : 999,
"Color" : "Black",
"Rating" : 4.7
}
{
"_id" : ObjectId("66ed2dcf46f537c4a934a815"),
"Name" : "OLED C1",
"Brand" : "LG",
"Cost" : 1299,
"Color" : "Black",
"Rating" : 4.8
}
{
"_id" : ObjectId("66ed2dcf46f537c4a934a816"),
"Name" : "QLED Q60",
"Brand" : "Samsung",
"Cost" : 899,
"Color" : "Silver",
"Rating" : 4.6
}
{
"_id" : ObjectId("66ed2dcf46f537c4a934a817"),
"Name" : "4K UHD 65",
"Brand" : "TCL",
"Cost" : 699,
"Color" : "Black",
"Rating" : 4.5
}
{
"_id" : ObjectId("66ed2dcf46f537c4a934a818"),
"Name" : "X900H",
"Brand" : "Sony",
"Cost" : 1199,
"Color" : "Black",
"Rating" : 4.7
}
{
"_id" : ObjectId("66ed2dcf46f537c4a934a819"),
"Name" : "Q70T",
"Brand" : "Samsung",
"Cost" : 999,
"Color" : "Gray",
"Rating" : 4.6
}
{
"_id" : ObjectId("66ed2dcf46f537c4a934a81a"),
"Name" : "CX OLED",
"Brand" : "LG",
"Cost" : 1399,
"Color" : "Black",
"Rating" : 4.9
}
{
"_id" : ObjectId("66ed2dcf46f537c4a934a81b"),
"Name" : "V-Series 50",
"Brand" : "Vizio",
"Cost" : 499,
"Color" : "Black",
"Rating" : 4.3
}
{
"_id" : ObjectId("66ed2dcf46f537c4a934a81c"),
"Name" : "H8G",
"Brand" : "Hisense",
"Cost" : 549,
"Color" : "Gray",
"Rating" : 4.2
}
{
"_id" : ObjectId("66ed2dcf46f537c4a934a81d"),
"Name" : "U7G",
"Brand" : "Hisense",
"Cost" : 799,
"Color" : "Silver",
"Rating" : 4.4
}
> db.Headphones.find().pretty()
{
"_id" : ObjectId("66ed2de946f537c4a934a81e"),
"Name" : "AirPods Pro",
"Brand" : "Apple",
"Cost" : 249,
"Color" : "White",
"Rating" : 4.7
}
{
"_id" : ObjectId("66ed2de946f537c4a934a81f"),
"Name" : "QC35 II",
"Brand" : "Bose",
"Cost" : 299,
"Color" : "Silver",
"Rating" : 4.8
}
{
"_id" : ObjectId("66ed2de946f537c4a934a820"),
"Name" : "WH-1000XM4",
"Brand" : "Sony",
"Cost" : 349,
"Color" : "Black",
"Rating" : 4.9
}
{
"_id" : ObjectId("66ed2de946f537c4a934a821"),
"Name" : "Galaxy Buds",
"Brand" : "Samsung",
"Cost" : 149,
"Color" : "White",
"Rating" : 4.5
}
{
"_id" : ObjectId("66ed2de946f537c4a934a822"),
"Name" : "Beats Studio3",
"Brand" : "Beats",
"Cost" : 349,
"Color" : "Red",
"Rating" : 4.6
}
{
"_id" : ObjectId("66ed2de946f537c4a934a823"),
"Name" : "QuietComfort Earbuds",
"Brand" : "Bose",
"Cost" : 279,
"Color" : "Black",
"Rating" : 4.7
}
{
"_id" : ObjectId("66ed2de946f537c4a934a824"),
"Name" : "Soundcore Q30",
"Brand" : "Anker",
"Cost" : 99,
"Color" : "Blue",
"Rating" : 4.4
}
{
"_id" : ObjectId("66ed2de946f537c4a934a825"),
"Name" : "Elite 85h",
"Brand" : "Jabra",
"Cost" : 249,
"Color" : "Black",
"Rating" : 4.6
}
{
"_id" : ObjectId("66ed2de946f537c4a934a826"),
"Name" : "Momentum 3",
"Brand" : "Sennheiser",
"Cost" : 399,
"Color" : "Gray",
"Rating" : 4.8
}
{
"_id" : ObjectId("66ed2de946f537c4a934a827"),
"Name" : "Pixel Buds",
"Brand" : "Google",
"Cost" : 179,
"Color" : "White",
"Rating" : 4.5
}
> db.Laptops.find().pretty()
{
"_id" : ObjectId("66ed2df846f537c4a934a828"),
"Name" : "MacBook Pro",
"Brand" : "Apple",
"Cost" : 1999,
"Color" : "Silver",
"Rating" : 4.9
}
{
"_id" : ObjectId("66ed2df846f537c4a934a829"),
"Name" : "XPS 13",
"Brand" : "Dell",
"Cost" : 1399,
"Color" : "Black",
"Rating" : 4.8
}
{
"_id" : ObjectId("66ed2df846f537c4a934a82a"),
"Name" : "ThinkPad X1",
"Brand" : "Lenovo",
"Cost" : 1599,
"Color" : "Black",
"Rating" : 4.7
}
{
"_id" : ObjectId("66ed2df846f537c4a934a82b"),
"Name" : "Surface Laptop 4",
"Brand" : "Microsoft",
"Cost" : 1299,
"Color" : "Platinum",
"Rating" : 4.6
}
{
"_id" : ObjectId("66ed2df846f537c4a934a82c"),
"Name" : "Yoga Slim 7i",
"Brand" : "Lenovo",
"Cost" : 999,
"Color" : "Gray",
"Rating" : 4.5
}
{
"_id" : ObjectId("66ed2df846f537c4a934a82d"),
"Name" : "Spectre x360",
"Brand" : "HP",
"Cost" : 1399,
"Color" : "Blue",
"Rating" : 4.7
}
{
"_id" : ObjectId("66ed2df846f537c4a934a82e"),
"Name" : "ROG Zephyrus G14",
"Brand" : "Asus",
"Cost" : 1449,
"Color" : "White",
"Rating" : 4.8
}
{
"_id" : ObjectId("66ed2df846f537c4a934a82f"),
"Name" : "Swift 3",
"Brand" : "Acer",
"Cost" : 799,
"Color" : "Silver",
"Rating" : 4.4
}
{
"_id" : ObjectId("66ed2df846f537c4a934a830"),
"Name" : "Blade 15",
"Brand" : "Razer",
"Cost" : 2499,
"Color" : "Black",
"Rating" : 4.9
}
{
"_id" : ObjectId("66ed2df846f537c4a934a831"),
"Name" : "Pavilion 15",
"Brand" : "HP",
"Cost" : 699,
"Color" : "Gold",
"Rating" : 4.2
}
> db.Watches.find().pretty()
> b.Watches.insertMany([
... { "Name": "Apple Watch Series 7", "Brand": "Apple", "Cost": 399, "Color":
"Black", "Rating": 4.8 },
... { "Name": "Galaxy Watch 4", "Brand": "Samsung", "Cost": 249, "Color":
"Silver", "Rating": 4.6 },
... { "Name": "Fitbit Sense", "Brand": "Fitbit", "Cost": 299, "Color": "Pink",
"Rating": 4.5 },
... { "Name": "Garmin Fenix 6", "Brand": "Garmin", "Cost": 599, "Color":
"Gray", "Rating": 4.7 },
... { "Name": "Amazfit GTR 3", "Brand": "Amazfit", "Cost": 179, "Color":
"Black", "Rating": 4.4 },
... { "Name": "TicWatch Pro 3", "Brand": "Mobvoi", "Cost": 299, "Color":
"Black", "Rating": 4.3 }])
uncaught exception: ReferenceError: b is not defined :
@(db.Watches.insertMany([{"Name":"Apple Watch Series
7","Brand":"Apple","Cost":399,"Color":"Black","Rating":4.8},{"Name":"Galaxy Watch
Series 8","Brand":"samsung","Cost":400,"Color":"Black","Rating":4.8},
{"Name":"pebble Watch Series
7","Brand":"pebble","Cost":1300,"Color":"Black","Rating":4.8}])
{
"acknowledged" : true,
"insertedIds" : [
ObjectId("66ed318546f537c4a934a832"),
ObjectId("66ed318546f537c4a934a833"),
ObjectId("66ed318546f537c4a934a834")
]
}
> db.Watches.find().pretty()
{
"_id" : ObjectId("66ed318546f537c4a934a832"),
"Name" : "Apple Watch Series 7",
"Brand" : "Apple",
"Cost" : 399,
"Color" : "Black",
"Rating" : 4.8
}
{
"_id" : ObjectId("66ed318546f537c4a934a833"),
"Name" : "Galaxy Watch Series 8",
"Brand" : "samsung",
"Cost" : 400,
"Color" : "Black",
"Rating" : 4.8
}
{
"_id" : ObjectId("66ed318546f537c4a934a834"),
"Name" : "pebble Watch Series 7",
"Brand" : "pebble",
"Cost" : 1300,
"Color" : "Black",
"Rating" : 4.8
}
> show collections
Headphones
Laptops
Mobiles
TV
Watches
> db.Laptops.find({"Name":"Macbook Pro"})
> db.Laptops.findOne("Brand":"Apple")
uncaught exception: SyntaxError: missing ) after argument list :
@(shell):1:26
> db.Laptops.findOne({"Brand":"Apple"})
{
"_id" : ObjectId("66ed2df846f537c4a934a828"),
"Name" : "MacBook Pro",
"Brand" : "Apple",
"Cost" : 1999,
"Color" : "Silver",
"Rating" : 4.9
}
> db.Watches.countDocuments()
uncaught exception: Error: command failed: {
"ok" : 0,
"errmsg" : "the match filter must be an expression in an object",
"code" : 15959,
"codeName" : "Location15959"
} with original command request: {
"aggregate" : "Watches",
"pipeline" : [
{
"$match" : undefined
},
{
"$group" : {
"_id" : null,
"n" : {
"$sum" : 1
}
}
}
],
"cursor" : {

},
"lsid" : {
"id" : UUID("55931698-927d-49c8-886b-d131aaf9a130")
}
} on connection: connection to 127.0.0.1:27017 : aggregate failed :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
doassert@src/mongo/shell/assert.js:18:14
_assertCommandWorked@src/mongo/shell/assert.js:760:17
assert.commandWorked@src/mongo/shell/assert.js:852:16
DB.prototype._runAggregate@src/mongo/shell/db.js:281:5
DBCollection.prototype.aggregate@src/mongo/shell/collection.js:1058:12
DBCollection.prototype.countDocuments@src/mongo/shell/collection.js:1455:17
@(shell):1:1
> db.Watches.count()
3
> db.Headphones.find({ "Cost": { $gt: 200 } })
{ "_id" : ObjectId("66ed2de946f537c4a934a81e"), "Name" : "AirPods Pro", "Brand" :
"Apple", "Cost" : 249, "Color" : "White", "Rating" : 4.7 }
{ "_id" : ObjectId("66ed2de946f537c4a934a81f"), "Name" : "QC35 II", "Brand" :
"Bose", "Cost" : 299, "Color" : "Silver", "Rating" : 4.8 }
{ "_id" : ObjectId("66ed2de946f537c4a934a820"), "Name" : "WH-1000XM4", "Brand" :
"Sony", "Cost" : 349, "Color" : "Black", "Rating" : 4.9 }
{ "_id" : ObjectId("66ed2de946f537c4a934a822"), "Name" : "Beats Studio3", "Brand" :
"Beats", "Cost" : 349, "Color" : "Red", "Rating" : 4.6 }
{ "_id" : ObjectId("66ed2de946f537c4a934a823"), "Name" : "QuietComfort Earbuds",
"Brand" : "Bose", "Cost" : 279, "Color" : "Black", "Rating" : 4.7 }
{ "_id" : ObjectId("66ed2de946f537c4a934a825"), "Name" : "Elite 85h", "Brand" :
"Jabra", "Cost" : 249, "Color" : "Black", "Rating" : 4.6 }
{ "_id" : ObjectId("66ed2de946f537c4a934a826"), "Name" : "Momentum 3", "Brand" :
"Sennheiser", "Cost" : 399, "Color" : "Gray", "Rating" : 4.8 }
> db.Mobiles.find({ "Brand": "Apple" })
{ "_id" : ObjectId("66ed2d9f46f537c4a934a80a"), "Name" : "iPhone 13", "Brand" :
"Apple", "Cost" : 799, "Color" : "Black", "Rating" : 4.8 }
{ "_id" : ObjectId("66ed2d9f46f537c4a934a810"), "Name" : "iPhone SE", "Brand" :
"Apple", "Cost" : 399, "Color" : "Red", "Rating" : 4.4 }
> db.Mobiles.find({ "Rating": "{gte:4.5" }})
uncaught exception: SyntaxError: missing ) after argument list :
@(shell):1:40
> db.Mobiles.find({ "Rating": {gte:4.5" }})
uncaught exception: SyntaxError: "" literal not terminated before end of script :
@(shell):1:41
> db.Mobiles.find({ "Rating": {$gte:4.5" }})
uncaught exception: SyntaxError: "" literal not terminated before end of script :
@(shell):1:42
> db.Laptops.find({ "Rating": {$gte:4.5" }})
uncaught exception: SyntaxError: "" literal not terminated before end of script :
@(shell):1:42
> db.Laptops.find({ "Rating": { $gte: 4.5 } })
{ "_id" : ObjectId("66ed2df846f537c4a934a828"), "Name" : "MacBook Pro", "Brand" :
"Apple", "Cost" : 1999, "Color" : "Silver", "Rating" : 4.9 }
{ "_id" : ObjectId("66ed2df846f537c4a934a829"), "Name" : "XPS 13", "Brand" :
"Dell", "Cost" : 1399, "Color" : "Black", "Rating" : 4.8 }
{ "_id" : ObjectId("66ed2df846f537c4a934a82a"), "Name" : "ThinkPad X1", "Brand" :
"Lenovo", "Cost" : 1599, "Color" : "Black", "Rating" : 4.7 }
{ "_id" : ObjectId("66ed2df846f537c4a934a82b"), "Name" : "Surface Laptop 4",
"Brand" : "Microsoft", "Cost" : 1299, "Color" : "Platinum", "Rating" : 4.6 }
{ "_id" : ObjectId("66ed2df846f537c4a934a82c"), "Name" : "Yoga Slim 7i", "Brand" :
"Lenovo", "Cost" : 999, "Color" : "Gray", "Rating" : 4.5 }
{ "_id" : ObjectId("66ed2df846f537c4a934a82d"), "Name" : "Spectre x360", "Brand" :
"HP", "Cost" : 1399, "Color" : "Blue", "Rating" : 4.7 }
{ "_id" : ObjectId("66ed2df846f537c4a934a82e"), "Name" : "ROG Zephyrus G14",
"Brand" : "Asus", "Cost" : 1449, "Color" : "White", "Rating" : 4.8 }
{ "_id" : ObjectId("66ed2df846f537c4a934a830"), "Name" : "Blade 15", "Brand" :
"Razer", "Cost" : 2499, "Color" : "Black", "Rating" : 4.9 }
> db.Laptops.find({ "Rating": { $gte: 4.5 } })

You might also like