Professional Documents
Culture Documents
Untitled
Untitled
Untitled
> db.stud.aggregate({$group:{_id:"$name","total":{$sum:1}}});
{ "_id" : "Shivani", "total" : 2 }
{ "_id" : "Shweta", "total" : 1 }
{ "_id" : "Shreya", "total" : 1 }
{ "_id" : "Shivu", "total" : 1 }
{ "_id" : "Shraddha", "total" : 1 }
> db.stud.aggregate({$group:{_id:"$name","total":{$max:"$amt"}}});
{ "_id" : "Shivani", "total" : "5000" }
{ "_id" : "Shweta", "total" : "2000" }
{ "_id" : "Shreya", "total" : "3000" }
{ "_id" : "Shivu", "total" : "2000" }
{ "_id" : "Shraddha", "total" : "1000" }
> db.stud.aggregate({$group:{_id:"$name","total":{$min:"$amt"}}});
{ "_id" : "Shivani", "total" : "1000" }
{ "_id" : "Shweta", "total" : "2000" }
{ "_id" : "Shreya", "total" : "3000" }
{ "_id" : "Shivu", "total" : "2000" }
{ "_id" : "Shraddha", "total" : "1000" }
> db.stud.aggregate({$group:{_id:"$name","total":{$first:"$amt"}}});
{ "_id" : "Shivani", "total" : "1000" }
{ "_id" : "Shweta", "total" : "2000" }
{ "_id" : "Shreya", "total" : "3000" }
{ "_id" : "Shivu", "total" : "2000" }
{ "_id" : "Shraddha", "total" : "1000" }
> db.stud.aggregate({$group:{_id:"$name","total":{$last:"$amt"}}});
{ "_id" : "Shivani", "total" : "5000" }
{ "_id" : "Shweta", "total" : "2000" }
{ "_id" : "Shreya", "total" : "3000" }
{ "_id" : "Shivu", "total" : "2000" }
{ "_id" : "Shraddha", "total" : "1000" }
> db.createCollection('Website2');
{ "ok" : 1 }
> db.Website2.insert({'rollno':'1','name':'Shraddha'});
WriteResult({ "nInserted" : 1 })
> db.Website2.insert({'rollno':'1','name':'Shraddha'});
WriteResult({ "nInserted" : 1 })
> db.Website2.find().pretty();
{
"_id" : ObjectId("6360f576c28b18142ad348e8"),
"rollno" : "1",
"name" : "Shraddha"
}
{
"_id" : ObjectId("6360f57bc28b18142ad348e9"),
"rollno" : "1",
"name" : "Shraddha"
}
>
> db.Website2.createIndex({'name':1});
{
"createdCollectionAutomatically" : false,
"numIndexesBefore" : 1,
"numIndexesAfter" : 2,
"ok" : 1
}
> db.Website2.createIndex({'name':-1});
{
"createdCollectionAutomatically" : false,
"numIndexesBefore" : 2,
"numIndexesAfter" : 3,
"ok" : 1
}
> db.Website2.getIndices();
[
{
"v" : 2,
"key" : {
"_id" : 1
},
"name" : "_id_",
"ns" : "shivani.Website2"
},
{
"v" : 2,
"key" : {
"name" : 1
},
"name" : "name_1",
"ns" : "shivani.Website2"
},
{
"v" : 2,
"key" : {
"name" : -1
},
"name" : "name_-1",
"ns" : "shivani.Website2"
}
]
> db.Website2.dropIndex({'name':1});
{ "nIndexesWas" : 3, "ok" : 1 }
> db.Website2.getIndices();
[
{
"v" : 2,
"key" : {
"_id" : 1
},
"name" : "_id_",
"ns" : "shivani.Website2"
},
{
"v" : 2,
"key" : {
"name" : -1
},
"name" : "name_-1",
"ns" : "shivani.Website2"
}
]
> db.Website2.dropIndex({'name':-1});
{ "nIndexesWas" : 2, "ok" : 1 }
> db.Website2.getIndices();
[
{
"v" : 2,
"key" : {
"_id" : 1
},
"name" : "_id_",
"ns" : "shivani.Website2"
}
]
>