Dbms
Dbms
switched to db db_!
Uncaught:
| ^
2|
switched to db db_1
db_1> db.createCollection("Posts")
{ ok: 1 }
acknowledged: true,
insertedId: ObjectId('6720d3873d84db951486b01d')
db_1> db.Posts.find()
_id: ObjectId('6720d3873d84db951486b01d'),
Role: 'Developer',
Age: 21,
Salary: 50000
}
db_1> db.Posts.find({"Age":20})
db_1> db.Posts.find({"Age":21})
_id: ObjectId('6720d3873d84db951486b01d'),
Role: 'Developer',
Age: 21,
Salary: 50000
db_1> db.Posts.insertMany([{"Name":"Ankush
Khairnar","Role":"Developer","Age":21,"Salary":50000},{"Name":"Rohan Nagare","Role":"Front-End
Devloper","Age":21,"Salary":60000},{"Name":"Vighnesh ise","Role":"Back-End
Devloper","Age":21,"Salary":50000}])
acknowledged: true,
insertedIds: {
'0': ObjectId('6720d5213d84db951486b01e'),
'1': ObjectId('6720d5213d84db951486b01f'),
'2': ObjectId('6720d5213d84db951486b020')
db_1> db.Posts.find()
_id: ObjectId('6720d3873d84db951486b01d'),
Role: 'Developer',
Age: 21,
Salary: 50000
},
_id: ObjectId('6720d5213d84db951486b01e'),
Role: 'Developer',
Age: 21,
Salary: 50000
},
_id: ObjectId('6720d5213d84db951486b01f'),
Age: 21,
Salary: 60000
},
_id: ObjectId('6720d5213d84db951486b020'),
Age: 21,
Salary: 50000
db_1> db.Posts.find({"Salary":50000})
_id: ObjectId('6720d3873d84db951486b01d'),
Role: 'Developer',
Age: 21,
Salary: 50000
},
_id: ObjectId('6720d5213d84db951486b01e'),
Role: 'Developer',
Age: 21,
Salary: 50000
},
_id: ObjectId('6720d5213d84db951486b020'),
Age: 21,
Salary: 50000
db_1> db.Posts.find({"Salary":50000}).sort({"Age":1})
_id: ObjectId('6720d3873d84db951486b01d'),
Role: 'Developer',
Age: 21,
Salary: 50000
},
_id: ObjectId('6720d5213d84db951486b01e'),
Role: 'Developer',
Age: 21,
Salary: 50000
},
_id: ObjectId('6720d5213d84db951486b020'),
Age: 21,
Salary: 50000
db_1> db.Posts.find({"Salary":50000}).sort({"Age":1}).skip(1).limit(3)
_id: ObjectId('6720d5213d84db951486b01e'),
Role: 'Developer',
Age: 21,
Salary: 50000
},
_id: ObjectId('6720d5213d84db951486b020'),
Age: 21,
Salary: 50000
db_1> db.createCollection('students')
{ ok: 1 }
db_1> db.students.insertMany([
... { "_id": 1, "name": "Alice", "marks": 85 },
... ]);
acknowledged: true,
db_1> db.students.find()
Uncaught:
| ^
2|
Uncaught:
2|
... total+=values[i]
... }
... };
... };
db_1> db.students.mapReduce(
... mapFunction,
... reduceFunction,
... {
... }
... );
Uncaught:
db_1> db.average_marks.find().pretty();
db_1> db.students.aggregate([
... {
... $group: {
... }
... }
... ]);
{ _id: 2, averageMarks: 70 },
{ _id: 3, averageMarks: 90 },
{ _id: 1, averageMarks: 85 },
{ _id: 4, averageMarks: 95 },
{ _id: 5, averageMarks: 80 }
db_1> db.createCollection('products')
{ ok: 1 }
db_1> db.orders.insertMany([
... { _id: 1, cust_id: "Ant O. Knee", ord_date: new Date("2020-03-01"), price: 25, items: [ { sku:
"oranges", qty: 5, price: 2.5 }, { sku: "apples", qty:
... { _id: 2, cust_id: "Ant O. Knee", ord_date: new Date("2020-03-08"), price: 70, items: [ { sku:
"oranges", qty: 8, price: 2.5 }, { sku: "chocolates", qty: 5, price: 10 } ], status: "A" },
... { _id: 3, cust_id: "Busby Bee", ord_date: new Date("2020-03-08"), price: 50, items: [ { sku:
"oranges", qty: 10, price: 2.5 }, { sku: "pears", qty: 10, price: 2.5 } ], status: "A" },
... { _id: 4, cust_id: "Busby Bee", ord_date: new Date("2020-03-18"), price: 25, items: [ { sku:
"oranges", qty: 10, price: 2.5 } ], status: "A" },
... { _id: 5, cust_id: "Busby Bee", ord_date: new Date("2020-03-19"), price: 50, items: [ { sku:
"chocolates", qty: 5, price: 10 } ], status: "A"},
... { _id: 6, cust_id: "Cam Elot", ord_date: new Date("2020-03-19"), price: 35, items: [ { sku:
"carrots", qty: 10, price: 1.0 }, { sku: "apples", qty: 10, price: 2.5 } ], status: "A" },
... { _id: 7, cust_id: "Cam Elot", ord_date: new Date("2020-03-20"), price: 25, items: [ { sku:
"oranges", qty: 10, price: 2.5 } ], status: "A" },
... { _id: 8, cust_id: "Don Quis", ord_date: new Date("2020-03-20"), price: 75, items: [ { sku:
"chocolates", qty: 5, price: 10 }, { sku: "apples", qty: 10, price: 2.5 } ], status: "A" },
... { _id: 9, cust_id: "Don Quis", ord_date: new Date("2020-03-20"), price: 55, items: [ { sku:
"carrots", qty: 5, price: 1.0 }, { sku: "apples", qty: 10, price: 2.5 }, { sku: "oranges", qty: 10, price:
2.5 } ], status: "A" },
... { _id: 10, cust_id: "Don Quis", ord_date: new Date("2020-03-23"), price: 25, items: [ { sku:
"oranges", qty: 10, price: 2.5 } ], status: "A" }
... ])
acknowledged: true,
insertedIds: {
'0': 1,
'1': 2,
'2': 3,
'3': 4,
'4': 5,
'5': 6,
'6': 7,
'7': 8,
'8': 9,
'9': 10
db_1>
db_1> db.products.find()
db_1> db.orders.find()
_id: 1,
ord_date: ISODate('2020-03-01T00:00:00.000Z'),
price: 25,
items: [
],
status: 'A'
},
_id: 2,
ord_date: ISODate('2020-03-08T00:00:00.000Z'),
price: 70,
items: [
],
status: 'A'
},
_id: 3,
ord_date: ISODate('2020-03-08T00:00:00.000Z'),
price: 50,
items: [
],
status: 'A'
},
_id: 4,
ord_date: ISODate('2020-03-18T00:00:00.000Z'),
price: 25,
status: 'A'
},
_id: 5,
ord_date: ISODate('2020-03-19T00:00:00.000Z'),
price: 50,
},
_id: 6,
ord_date: ISODate('2020-03-19T00:00:00.000Z'),
price: 35,
items: [
],
status: 'A'
},
_id: 7,
ord_date: ISODate('2020-03-20T00:00:00.000Z'),
price: 25,
status: 'A'
},
_id: 8,
ord_date: ISODate('2020-03-20T00:00:00.000Z'),
price: 75,
items: [
],
status: 'A'
},
_id: 9,
ord_date: ISODate('2020-03-20T00:00:00.000Z'),
price: 55,
items: [
],
status: 'A'
},
_id: 10,
ord_date: ISODate('2020-03-23T00:00:00.000Z'),
price: 25,
status: 'A'
... };
db_1> db.orders.mapReduce(
... mapFunction1,
... reduceFunction1,
... { out: "map_reduce_example" }
... )
db_1> db.createCollection("Student")
{ ok: 1 }
db_1> db.students.insertMany([
...
db_1> db.createCollection("student")
{ ok: 1 }
db_1> db.createCollection("students")
{ ok: 1 }
db_1> db.students.insertMany([
Uncaught:
MongoBulkWriteError: E11000 duplicate key error collection: db_1.students index: _id_ dup key:
{ _id: 1 }
Result: BulkWriteResult {
insertedCount: 0,
matchedCount: 0,
modifiedCount: 0,
deletedCount: 0,
upsertedCount: 0,
upsertedIds: {},
insertedIds: {}
Write Errors: [
WriteError {
err: {
index: 0,
code: 11000,
errmsg: 'E11000 duplicate key error collection: db_1.students index: _id_ dup key: { _id: 1 }',
errInfo: undefined,
db_1> db.students.drop();
true
db_1> db.createCollection("students")
{ ok: 1 }
{
acknowledged: true,
db_1> db.students.find()
db_1> db.students.aggregate([
... {$group
...
db_1> db.students.aggregate([{
db_1> db.students.aggregate([{
... }
... }
... )];
Uncaught:
3|}
4|}
> 5 | )];
|^
6|
db_1> db.students.aggregate([
... {
... $group: {
... }
... }
... ]);
db_1> db.students.aggregate([
... {
... $group:
... {
... id:"$name",average:{$avg:"$marks"}
... }
... }
... ]);
name_1
db_1> db.students.getIndexes();
name_1_marks_-1
db_1> db.students.getIndexes();
db_1>