0% found this document useful (0 votes)
52 views3 pages

NOSQL6 TH Nov

Uploaded by

Rutuja Bhagat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views3 pages

NOSQL6 TH Nov

Uploaded by

Rutuja Bhagat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

Last login: Wed Nov 6 11:35:20 on ttys000

(base) ruu-bhagat@Ruus-MacBook-Air ~ % mongosh


Current Mongosh Log ID: 672b0fcc43ef078700aab33c
Connecting to: mongodb://127.0.0.1:27017/?
directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+2.3.3
Using MongoDB: 6.0.18
Using Mongosh: 2.3.3

For mongosh info see: https://www.mongodb.com/docs/mongodb-shell/

------
The server generated these startup warnings when booting
2024-11-06T10:51:28.327+05:30: Access control is not enabled for the database.
Read and write access to data and configuration is unrestricted
------

test> db.products.insertOne({item:"card", qty: 15})


{
acknowledged: true,
insertedId: ObjectId('672b0ff443ef078700aab33d')
}
test> db.products.insertOne( { _id: 10, "item" : "peanuts", "qty" : 200 } )
{ acknowledged: true, insertedId: 10 }
test> db.products.insertMany( [
... { item: "card", qty: 15 },
... { item: "envelope", qty: 20 },
... { item: "stamps" , qty: 30 }
... ] );
{
acknowledged: true,
insertedIds: {
'0': ObjectId('672b103743ef078700aab33e'),
'1': ObjectId('672b103743ef078700aab33f'),
'2': ObjectId('672b103743ef078700aab340')
}
}
test> db.inventory.insertMany([
... { "item": "journal", "qty": 25, "size": { "h": 14, "w": 21, "uom": "cm" },
"status": "A" },
... { "item": "notebook", "qty": 50, "size": { "h": 8.5, "w": 11, "uom":
"in" }, "status": "A" },
... { "item": "paper", "qty": 100, "size": { "h": 8.5, "w": 11, "uom": "in" },
"status": "D" },
... { "item": "planner", "qty": 75, "size": { "h": 22.85, "w": 30, "uom":
"cm" }, "status": "D" },
... { "item": "postcard", "qty": 45, "size": { "h": 10, "w": 15.25, "uom": "cm"
}, "status": "A" }
...
... ]);
{
acknowledged: true,
insertedIds: {
'0': ObjectId('672b104043ef078700aab341'),
'1': ObjectId('672b104043ef078700aab342'),
'2': ObjectId('672b104043ef078700aab343'),
'3': ObjectId('672b104043ef078700aab344'),
'4': ObjectId('672b104043ef078700aab345')
}
}
test> {status: {$in: ["D"]}}
[ 'D' ]
test> db.products.find{status: {$in: ["D"]}}
Uncaught:
SyntaxError: Missing semicolon. (1:16)

> 1 | db.products.find{status: {$in: ["D"]}}


| ^
2 |

test> db.products.find({status: {$in: ["D"]}})

test> db.products.find({status: {$in: ["A"]}})

test> db.products.findMany({status: {$in: ["A"]}})


TypeError: db.products.findMany is not a function
test> db.products.findOne({status: {$in: ["A"]}})
null
test> db.products.findOne({status: {$in: ["D"]}})
null
test> db.inventory.find({ status: "D" })
[
{
_id: ObjectId('672b104043ef078700aab343'),
item: 'paper',
qty: 100,
size: { h: 8.5, w: 11, uom: 'in' },
status: 'D'
},
{
_id: ObjectId('672b104043ef078700aab344'),
item: 'planner',
qty: 75,
size: { h: 22.85, w: 30, uom: 'cm' },
status: 'D'
}
]
test> db.inventory.find({ status: { $in: ["A", "D"] } })
[
{
_id: ObjectId('672b104043ef078700aab341'),
item: 'journal',
qty: 25,
size: { h: 14, w: 21, uom: 'cm' },
status: 'A'
},
{
_id: ObjectId('672b104043ef078700aab342'),
item: 'notebook',
qty: 50,
size: { h: 8.5, w: 11, uom: 'in' },
status: 'A'
},
{
_id: ObjectId('672b104043ef078700aab343'),
item: 'paper',
qty: 100,
size: { h: 8.5, w: 11, uom: 'in' },
status: 'D'
},
{
_id: ObjectId('672b104043ef078700aab344'),
item: 'planner',
qty: 75,
size: { h: 22.85, w: 30, uom: 'cm' },
status: 'D'
},
{
_id: ObjectId('672b104043ef078700aab345'),
item: 'postcard',
qty: 45,
size: { h: 10, w: 15.25, uom: 'cm' },
status: 'A'
}
]
test> db.inventory.find({ status: "A", qty: { $lt: 30 } })
[
{
_id: ObjectId('672b104043ef078700aab341'),
item: 'journal',
qty: 25,
size: { h: 14, w: 21, uom: 'cm' },
status: 'A'
}
]
test> db.inventory.insertOne({"item":"journal2","qty":23,"size":
{"h":13,"w":21,"uom":"cm"},"status":"A"});
{
acknowledged: true,
insertedId: ObjectId('672b140c43ef078700aab346')
}
test> db.inventory.find({ status: "A", $or: [ { qty: { $lt: 30 } }, { item:
/^p/ } ] })
[
{
_id: ObjectId('672b104043ef078700aab341'),
item: 'journal',
qty: 25,
size: { h: 14, w: 21, uom: 'cm' },
status: 'A'
},
{
_id: ObjectId('672b104043ef078700aab345'),
item: 'postcard',
qty: 45,
size: { h: 10, w: 15.25, uom: 'cm' },
status: 'A'
},
{
_id: ObjectId('672b140c43ef078700aab346'),
item: 'journal2',
qty: 23,
size: { h: 13, w: 21, uom: 'cm' },
status: 'A'
}
]
test>

You might also like