Nosql
Nosql
{"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
------
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
------
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 }}
]
}
]
})