0% found this document useful (0 votes)
56 views11 pages

Nosql

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)
56 views11 pages

Nosql

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/ 11

84928, "ctx":"initandlisten","msg":"Shutting down the TTL monitor"}

{"t":{"$date":"2024-11-05T08:25:18.304+05:30"},"s":"I", "c":"CONTROL",
"id":6278511, "ctx":"initandlisten","msg":"Shutting down the Change Stream Expired
Pre-images Remover"}
{"t":{"$date":"2024-11-05T08:25:18.304+05:30"},"s":"I", "c":"CONTROL",
"id":4784929, "ctx":"initandlisten","msg":"Acquiring the global lock for shutdown"}
{"t":{"$date":"2024-11-05T08:25:18.304+05:30"},"s":"I", "c":"-",
"id":4784931, "ctx":"initandlisten","msg":"Dropping the scope cache for shutdown"}
{"t":{"$date":"2024-11-05T08:25:18.304+05:30"},"s":"I", "c":"CONTROL",
"id":20565, "ctx":"initandlisten","msg":"Now exiting"}
{"t":{"$date":"2024-11-05T08:25:18.304+05:30"},"s":"I", "c":"CONTROL",
"id":8423404, "ctx":"initandlisten","msg":"mongod shutdown complete","attr":
{"Summary of time elapsed":{"Statistics":{"Enter terminal shutdown":"0 ms","Step
down the replication coordinator for shutdown":"0 ms","Time spent in quiesce
mode":"1 ms","Shut down FLE Crud subsystem":"0 ms","Shut down MirrorMaestro":"0
ms","Shut down WaitForMajorityService":"0 ms","Shut down the global connection
pool":"0 ms","Shut down the replica set monitor":"0 ms","Shut down the migration
util executor":"0 ms","Shut down the TTL monitor":"0 ms","Shut down expired pre-
images remover":"0 ms","Shut down full-time data capture":"0 ms","shutdownTask
total elapsed time":"1 ms"}}}}
{"t":{"$date":"2024-11-05T08:25:18.304+05:30"},"s":"I", "c":"CONTROL",
"id":23138, "ctx":"initandlisten","msg":"Shutting down","attr":{"exitCode":48}}
ruu-bhagat@Ruus-MacBook-Air ~ % clear

ruu-bhagat@Ruus-MacBook-Air ~ % brew services start mongodb/brew/mongodb-community


Error: Formula `mongodb-community` is not installed.
ruu-bhagat@Ruus-MacBook-Air ~ % mongosh
Current Mongosh Log ID: 67298937675ff91693b6e70e
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-05T08:07:08.649+05:30: Access control is not enabled for the database.
Read and write access to data and configuration is unrestricted
------

test> show dbs


admin 40.00 KiB
config 60.00 KiB
local 72.00 KiB
test> use classc
switched to db classc
classc> db.students.insertMany([
... { name: "Alice", age: 20, grade: "A", subjects: ["Math", "English"] },
... { name: "Bob", age: 21, grade: "B", subjects: ["Science", "History"] },
... { name: "Charlie", age: 22, grade: "A", subjects: ["Math", "Physics"] },
... { name: "David", age: 23, grade: "C", subjects: ["English", "Arts"] }
... ])
{
acknowledged: true,
insertedIds: {
'0': ObjectId('672989b1675ff91693b6e70f'),
'1': ObjectId('672989b1675ff91693b6e710'),
'2': ObjectId('672989b1675ff91693b6e711'),
'3': ObjectId('672989b1675ff91693b6e712')
}
}
classc> db.students.find().pretty()
[
{
_id: ObjectId('672989b1675ff91693b6e70f'),
name: 'Alice',
age: 20,
grade: 'A',
subjects: [ 'Math', 'English' ]
},
{
_id: ObjectId('672989b1675ff91693b6e710'),
name: 'Bob',
age: 21,
grade: 'B',
subjects: [ 'Science', 'History' ]
},
{
_id: ObjectId('672989b1675ff91693b6e711'),
name: 'Charlie',
age: 22,
grade: 'A',
subjects: [ 'Math', 'Physics' ]
},
{
_id: ObjectId('672989b1675ff91693b6e712'),
name: 'David',
age: 23,
grade: 'C',
subjects: [ 'English', 'Arts' ]
}
]
classc> db.students.find({ grade: "A" })
[
{
_id: ObjectId('672989b1675ff91693b6e70f'),
name: 'Alice',
age: 20,
grade: 'A',
subjects: [ 'Math', 'English' ]
},
{
_id: ObjectId('672989b1675ff91693b6e711'),
name: 'Charlie',
age: 22,
grade: 'A',
subjects: [ 'Math', 'Physics' ]
}
]
classc> db.students.updateOne({ name: "Bob" }, { $set: { grade: "A" } })
{
acknowledged: true,
insertedId: null,
matchedCount: 1,
modifiedCount: 1,
upsertedCount: 0
}
classc> show sbs
MongoshInvalidInputError: [COMMON-10001] 'sbs' is not a valid argument for "show".
classc> show dbs
admin 40.00 KiB
classc 8.00 KiB
config 108.00 KiB
local 72.00 KiB
classc> use class
switched to db class
class> db.createCollection("sample")
{ ok: 1 }
class> show collections
sample
class> db.sample.insert({Name:"Rutuja"})
DeprecationWarning: Collection.insert() is deprecated. Use insertOne, insertMany,
or bulkWrite.
{
acknowledged: true,
insertedIds: { '0': ObjectId('67298aea675ff91693b6e713') }
}
class> db.sample.insertOne({Name:"Rutuja"
... db.sample.insertOne({Name:"Rutuja"})
Uncaught:
SyntaxError: Unexpected token, expected "," (2:0)

1 | db.sample.insertOne({Name:"Rutuja"
> 2 | db.sample.insertOne({Name:"Rutuja"})
| ^
3 |

class> db.sample.insertOne({Name:"Rutuja"})
{
acknowledged: true,
insertedId: ObjectId('67298b12675ff91693b6e714')
}
class> db.sample.find()
[
{ _id: ObjectId('67298aea675ff91693b6e713'), Name: 'Rutuja' },
{ _id: ObjectId('67298b12675ff91693b6e714'), Name: 'Rutuja' }
]
class> db.sample.find().pretty()
[
{ _id: ObjectId('67298aea675ff91693b6e713'), Name: 'Rutuja' },
{ _id: ObjectId('67298b12675ff91693b6e714'), Name: 'Rutuja' }
]
class> db.sample.insertMany([{Name:"John",Age:12},{Name:"Jay",Age:14}])
{
acknowledged: true,
insertedIds: {
'0': ObjectId('67298d5c675ff91693b6e715'),
'1': ObjectId('67298d5c675ff91693b6e716')
}
}
class> db.sample.find()
[
{ _id: ObjectId('67298aea675ff91693b6e713'), Name: 'Rutuja' },
{ _id: ObjectId('67298b12675ff91693b6e714'), Name: 'Rutuja' },
{ _id: ObjectId('67298d5c675ff91693b6e715'), Name: 'John', Age: 12 },
{ _id: ObjectId('67298d5c675ff91693b6e716'), Name: 'Jay', Age: 14 }
]
class> db.employee.insert([
... {
... "EmpNo":"1",
... "FirstName":"Andrew",
... "LastName":"Neil",
... "Age":"30",
... "Gender":"Male",
... "Skill":"MongoDB",
... "Phone":"408-1234567",
... "Email":"[email protected]",
... "Salary":"80000"
... },
... {
... "EmpNo":"2",
... "FirstName":"Brian",
... "LastName":"Hall",
... "Age":"27",
... "Gender":"Male",
... "Skill":"Javascript",
... "Phone":"408-1298367",
... "Email":"[email protected]",
... "Salary":"60000"
... },
... {
... "EmpNo":"3",
... "FirstName":"Chris",
... "LastName":"White",
... "Age":"40",
... "Gender":"Male",
... "Skill":"Python",
... "Phone":"408-4444567",
... "Email":"[email protected]",
... "Salary":"100000"
... },
... {
... "EmpNo":"4",
... "FirstName":"Debbie",
... "LastName":"Long",
... "Age":"32",
... "Gender":"Female",
... "Skill":"Project Management",
... "Phone":"408-1299963",
... "Email":"[email protected]",
... "Salary":"105000"
... },
... {
... "EmpNo":"5",
... "FirstName":"Ethan",
... "LastName":"Murphy",
... "Age":"45",
... "Gender":"Male",
... "Skill":"C#",
... "Phone":"408-3314567",
... "Email":"[email protected]",
... "Salary":"120000"
... }])
{
acknowledged: true,
insertedIds: {
'0': ObjectId('67298da1675ff91693b6e717'),
'1': ObjectId('67298da1675ff91693b6e718'),
'2': ObjectId('67298da1675ff91693b6e719'),
'3': ObjectId('67298da1675ff91693b6e71a'),
'4': ObjectId('67298da1675ff91693b6e71b')
}
}
class> db.sample.find()
[
{ _id: ObjectId('67298aea675ff91693b6e713'), Name: 'Rutuja' },
{ _id: ObjectId('67298b12675ff91693b6e714'), Name: 'Rutuja' },
{ _id: ObjectId('67298d5c675ff91693b6e715'), Name: 'John', Age: 12 },
{ _id: ObjectId('67298d5c675ff91693b6e716'), Name: 'Jay', Age: 14 }
]
class> db.employee.find()
[
{
_id: ObjectId('67298da1675ff91693b6e717'),
EmpNo: '1',
FirstName: 'Andrew',
LastName: 'Neil',
Age: '30',
Gender: 'Male',
Skill: 'MongoDB',
Phone: '408-1234567',
Email: '[email protected]',
Salary: '80000'
},
{
_id: ObjectId('67298da1675ff91693b6e718'),
EmpNo: '2',
FirstName: 'Brian',
LastName: 'Hall',
Age: '27',
Gender: 'Male',
Skill: 'Javascript',
Phone: '408-1298367',
Email: '[email protected]',
Salary: '60000'
},
{
_id: ObjectId('67298da1675ff91693b6e719'),
EmpNo: '3',
FirstName: 'Chris',
LastName: 'White',
Age: '40',
Gender: 'Male',
Skill: 'Python',
Phone: '408-4444567',
Email: '[email protected]',
Salary: '100000'
},
{
_id: ObjectId('67298da1675ff91693b6e71a'),
EmpNo: '4',
FirstName: 'Debbie',
LastName: 'Long',
Age: '32',
Gender: 'Female',
Skill: 'Project Management',
Phone: '408-1299963',
Email: '[email protected]',
Salary: '105000'
},
{
_id: ObjectId('67298da1675ff91693b6e71b'),
EmpNo: '5',
FirstName: 'Ethan',
LastName: 'Murphy',
Age: '45',
Gender: 'Male',
Skill: 'C#',
Phone: '408-3314567',
Email: '[email protected]',
Salary: '120000'
}
]
class> db.employee.findOne
[Function: findOne] AsyncFunction {
apiVersions: [ 1, Infinity ],
returnType: 'Document',
returnsPromise: true,
serverVersions: [ '0.0.0', '999.999.999' ],
topologies: [ 'ReplSet', 'Sharded', 'LoadBalanced', 'Standalone' ],
deprecated: false,
platforms: [ 'Compass', 'Browser', 'CLI' ],
isDirectShellCommand: false,
acceptsRawInput: false,
shellCommandCompleter: undefined,
help: [Function (anonymous)] Help
}
class> db.employee.findOne()
{
_id: ObjectId('67298da1675ff91693b6e717'),
EmpNo: '1',
FirstName: 'Andrew',
LastName: 'Neil',
Age: '30',
Gender: 'Male',
Skill: 'MongoDB',
Phone: '408-1234567',
Email: '[email protected]',
Salary: '80000'
}
class> db
class
class> db.employee.findOne(2)
MongoInvalidArgumentError: Query filter must be a plain object or ObjectId
class> db.employee.find(2)
MongoInvalidArgumentError: Query filter must be a plain object or ObjectId
class> db.employee.find({EmpNo:2})

class> db.employee.find({EmpId:2})

class> db.employee.find({empid:2})

class> db.employee.find({EmpNo:2})
class> db.employee.find({EmpNo:"2"})
[
{
_id: ObjectId('67298da1675ff91693b6e718'),
EmpNo: '2',
FirstName: 'Brian',
LastName: 'Hall',
Age: '27',
Gender: 'Male',
Skill: 'Javascript',
Phone: '408-1298367',
Email: '[email protected]',
Salary: '60000'
}
]
class> db.employee.find({FirstName:"Andrew"})
[
{
_id: ObjectId('67298da1675ff91693b6e717'),
EmpNo: '1',
FirstName: 'Andrew',
LastName: 'Neil',
Age: '30',
Gender: 'Male',
Skill: 'MongoDB',
Phone: '408-1234567',
Email: '[email protected]',
Salary: '80000'
}
]
class> db.employee.find({firstName:"Andrew"})

class> db.employee.find({firstName:"andrew"}
... )

class> db.employee.find({FirstName:"Andrew"})
[
{
_id: ObjectId('67298da1675ff91693b6e717'),
EmpNo: '1',
FirstName: 'Andrew',
LastName: 'Neil',
Age: '30',
Gender: 'Male',
Skill: 'MongoDB',
Phone: '408-1234567',
Email: '[email protected]',
Salary: '80000'
}
]
class> db.employee.find({Age<'30'})
Uncaught:
SyntaxError: Unexpected token, expected "," (1:21)

> 1 | db.employee.find({Age<'30'})
| ^
2 |
class> db.employee.find({Age:{$lt:30}})

class> db.employee.find({Age:{$lt:'30'}})
[
{
_id: ObjectId('67298da1675ff91693b6e718'),
EmpNo: '2',
FirstName: 'Brian',
LastName: 'Hall',
Age: '27',
Gender: 'Male',
Skill: 'Javascript',
Phone: '408-1298367',
Email: '[email protected]',
Salary: '60000'
}
]
class> db.employee.find({Age:{$lte:'30'}})
[
{
_id: ObjectId('67298da1675ff91693b6e717'),
EmpNo: '1',
FirstName: 'Andrew',
LastName: 'Neil',
Age: '30',
Gender: 'Male',
Skill: 'MongoDB',
Phone: '408-1234567',
Email: '[email protected]',
Salary: '80000'
},
{
_id: ObjectId('67298da1675ff91693b6e718'),
EmpNo: '2',
FirstName: 'Brian',
LastName: 'Hall',
Age: '27',
Gender: 'Male',
Skill: 'Javascript',
Phone: '408-1298367',
Email: '[email protected]',
Salary: '60000'
}
]
class> db.employee.find({Age:{$ne:'30'}})
[
{
_id: ObjectId('67298da1675ff91693b6e718'),
EmpNo: '2',
FirstName: 'Brian',
LastName: 'Hall',
Age: '27',
Gender: 'Male',
Skill: 'Javascript',
Phone: '408-1298367',
Email: '[email protected]',
Salary: '60000'
},
{
_id: ObjectId('67298da1675ff91693b6e719'),
EmpNo: '3',
FirstName: 'Chris',
LastName: 'White',
Age: '40',
Gender: 'Male',
Skill: 'Python',
Phone: '408-4444567',
Email: '[email protected]',
Salary: '100000'
},
{
_id: ObjectId('67298da1675ff91693b6e71a'),
EmpNo: '4',
FirstName: 'Debbie',
LastName: 'Long',
Age: '32',
Gender: 'Female',
Skill: 'Project Management',
Phone: '408-1299963',
Email: '[email protected]',
Salary: '105000'
},
{
_id: ObjectId('67298da1675ff91693b6e71b'),
EmpNo: '5',
FirstName: 'Ethan',
LastName: 'Murphy',
Age: '45',
Gender: 'Male',
Skill: 'C#',
Phone: '408-3314567',
Email: '[email protected]',
Salary: '120000'
}
]
class> db.employee.find({Skill:{$ne:'MongoDB'}})
[
{
_id: ObjectId('67298da1675ff91693b6e718'),
EmpNo: '2',
FirstName: 'Brian',
LastName: 'Hall',
Age: '27',
Gender: 'Male',
Skill: 'Javascript',
Phone: '408-1298367',
Email: '[email protected]',
Salary: '60000'
},
{
_id: ObjectId('67298da1675ff91693b6e719'),
EmpNo: '3',
FirstName: 'Chris',
LastName: 'White',
Age: '40',
Gender: 'Male',
Skill: 'Python',
Phone: '408-4444567',
Email: '[email protected]',
Salary: '100000'
},
{
_id: ObjectId('67298da1675ff91693b6e71a'),
EmpNo: '4',
FirstName: 'Debbie',
LastName: 'Long',
Age: '32',
Gender: 'Female',
Skill: 'Project Management',
Phone: '408-1299963',
Email: '[email protected]',
Salary: '105000'
},
{
_id: ObjectId('67298da1675ff91693b6e71b'),
EmpNo: '5',
FirstName: 'Ethan',
LastName: 'Murphy',
Age: '45',
Gender: 'Male',
Skill: 'C#',
Phone: '408-3314567',
Email: '[email protected]',
Salary: '120000'
}
]
class> db.employee.find({Skill:'MongoDB'})
[
{
_id: ObjectId('67298da1675ff91693b6e717'),
EmpNo: '1',
FirstName: 'Andrew',
LastName: 'Neil',
Age: '30',
Gender: 'Male',
Skill: 'MongoDB',
Phone: '408-1234567',
Email: '[email protected]',
Salary: '80000'
}
]
class> db.employee.find({Skill:'MongoDB'}).count()
(node:31193) [MONGODB DRIVER] Warning: cursor.count is deprecated and will be
removed in the next major version, please use `collection.estimatedDocumentCount`
or `collection.countDocuments` instead
(Use `node --trace-warnings ...` to show where the warning was created)
1
class> db.employee.find({Skill:'MongoDB'}).count();
1
class> db.employee.find({Skill:'MongoDB',Salary:'80000'})
[
{
_id: ObjectId('67298da1675ff91693b6e717'),
EmpNo: '1',
FirstName: 'Andrew',
LastName: 'Neil',
Age: '30',
Gender: 'Male',
Skill: 'MongoDB',
Phone: '408-1234567',
Email: '[email protected]',
Salary: '80000'
}
]
class> db.employee.find({$or[{Skill:"MongoDB"},{Salary:"80000"}])
Uncaught:
SyntaxError: Unexpected token, expected "," (1:21)

> 1 | db.employee.find({$or[{Skill:"MongoDB"},{Salary:"80000"}])
| ^
2 |

class> db.employee.find($or[{Skill:"MongoDB"},{Salary:"80000"}])
ReferenceError: $or is not defined
class> db.employee.find({$or:[{Skill:"MongoDB"},{Salary:"80000"}])
Uncaught:
SyntaxError: Unexpected token, expected "," (1:58)

> 1 | db.employee.find({$or:[{Skill:"MongoDB"},{Salary:"80000"}])
| ^
2 |

class> db.employee.find({$or:[{Skill:"MongoDB"},{Salary:"80000"}]})
[
{
_id: ObjectId('67298da1675ff91693b6e717'),
EmpNo: '1',
FirstName: 'Andrew',
LastName: 'Neil',
Age: '30',
Gender: 'Male',
Skill: 'MongoDB',
Phone: '408-1234567',
Email: '[email protected]',
Salary: '80000'
}
]
class>
class> db.employee.find({$and:[{Salary:{$gt:"30000"},{Salary:{$lt:"80000"})}]})

db.employee.find({
$and: [
{
$or: [
{ Salary: { $gt: 30000, $lt: 80000 } },
{ Salary: { $lt: 30000 }}
]
}
]
})

You might also like