Добавил:
nyan
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:7 семестр - ИПОВС / Готовые лабы / Lab3
.txt > db.col_test_1.find(null, {firstName:1})
{ "_id" : ObjectId("5ba90752373e73b21e346f3a"), "firstName" : "Igor" }
{ "_id" : ObjectId("5ba90778373e73b21e346f3b"), "firstName" : "Andrey" }
{ "_id" : ObjectId("5ba9079a373e73b21e346f3c"), "firstName" : "Helen" }
{ "_id" : ObjectId("5ba907b9373e73b21e346f3d"), "firstName" : "NoName" }
{ "_id" : ObjectId("5ba907dc373e73b21e346f3e"), "firstName" : "Alexey" }
{ "_id" : ObjectId("5bcdf3afa7c67da00d165377"), "firstName" : "Natasha" }
> db.col_test_1.find(null, {creationDate:0, lastSess:0})
{ "_id" : ObjectId("5ba90752373e73b21e346f3a"), "index" : 1, "firstName" : "Igor", "lastName" : "Zolotarev", "age" : 21, "subjects" : [ "Math", "Physics" ] }
{ "_id" : ObjectId("5ba90778373e73b21e346f3b"), "index" : 1, "firstName" : "Andrey", "lastName" : "Zolotarev", "age" : 46, "subjects" : [ ] }
{ "_id" : ObjectId("5ba9079a373e73b21e346f3c"), "subjects" : [ "math", "art" ], "firstName" : "Helen", "lastName" : "Iriarte", "index" : 21 }
{ "_id" : ObjectId("5ba907b9373e73b21e346f3d"), "index" : 2, "firstName" : "NoName", "lastName" : "NoName", "age" : 0, "subjects" : [ ] }
{ "_id" : ObjectId("5ba907dc373e73b21e346f3e"), "index" : 3, "firstName" : "Alexey", "lastName" : "Maslov", "age" : 40, "subjects" : [ "Marketing" ] }
{ "_id" : ObjectId("5bcdf3afa7c67da00d165377"), "firstName" : "Natasha" }
> db.col_test_1.find(null, {firstName:1, _id:0})
{ "firstName" : "Igor" }
{ "firstName" : "Andrey" }
{ "firstName" : "Helen" }
{ "firstName" : "NoName" }
{ "firstName" : "Alexey" }
{ "firstName" : "Natasha" }
> db.col_test_1.find(null, {firstName:1}).sort({firstName:-1})
{ "_id" : ObjectId("5ba907b9373e73b21e346f3d"), "firstName" : "NoName" }
{ "_id" : ObjectId("5bcdf3afa7c67da00d165377"), "firstName" : "Natasha" }
{ "_id" : ObjectId("5ba90752373e73b21e346f3a"), "firstName" : "Igor" }
{ "_id" : ObjectId("5ba9079a373e73b21e346f3c"), "firstName" : "Helen" }
{ "_id" : ObjectId("5ba90778373e73b21e346f3b"), "firstName" : "Andrey" }
{ "_id" : ObjectId("5ba907dc373e73b21e346f3e"), "firstName" : "Alexey" }
> db.col_test_1.find(null, {firstName:1}).sort({firstName:1})
{ "_id" : ObjectId("5ba907dc373e73b21e346f3e"), "firstName" : "Alexey" }
{ "_id" : ObjectId("5ba90778373e73b21e346f3b"), "firstName" : "Andrey" }
{ "_id" : ObjectId("5ba9079a373e73b21e346f3c"), "firstName" : "Helen" }
{ "_id" : ObjectId("5ba90752373e73b21e346f3a"), "firstName" : "Igor" }
{ "_id" : ObjectId("5bcdf3afa7c67da00d165377"), "firstName" : "Natasha" }
{ "_id" : ObjectId("5ba907b9373e73b21e346f3d"), "firstName" : "NoName" }
db.col_test_1.find(null, {firstName:1}).sort({firstName:1}).limit(5)
{ "_id" : ObjectId("5ba907dc373e73b21e346f3e"), "firstName" : "Alexey" }
{ "_id" : ObjectId("5ba90778373e73b21e346f3b"), "firstName" : "Andrey" }
{ "_id" : ObjectId("5ba9079a373e73b21e346f3c"), "firstName" : "Helen" }
{ "_id" : ObjectId("5ba90752373e73b21e346f3a"), "firstName" : "Igor" }
{ "_id" : ObjectId("5bcdf3afa7c67da00d165377"), "firstName" : "Natasha" }
> db.col_test_1.find(null, {firstName:1}).sort({firstName:1}).skip(3)
{ "_id" : ObjectId("5ba90752373e73b21e346f3a"), "firstName" : "Igor" }
{ "_id" : ObjectId("5bcdf3afa7c67da00d165377"), "firstName" : "Natasha" }
{ "_id" : ObjectId("5ba907b9373e73b21e346f3d"), "firstName" : "NoName" }
> db.col_test_1.find(null, {firstName:1}).sort({firstName:1}).skip(3).limit(5)
{ "_id" : ObjectId("5ba90752373e73b21e346f3a"), "firstName" : "Igor" }
{ "_id" : ObjectId("5bcdf3afa7c67da00d165377"), "firstName" : "Natasha" }
{ "_id" : ObjectId("5ba907b9373e73b21e346f3d"), "firstName" : "NoName" }
> db.col_test_1.find(null, {firstName:1}).sort({firstName:1}).skip(3).count(1)
3
> db.col_test_1.find(null, {firstName:1}).sort({firstName:1}).skip(3).limit(5).count(1)
3
> db.col_test_1.find(null, {firstName:1}).sort({firstName:1}).limit(5).count(1)
5
> db.col_test_1.count()
6
> var b=0
> var a=0
> var c=1
> db.col_lab_2.find().forEach(function(doc) {if(doc.number>0) a+=doc.number;})
> a
18
> db.col_lab_2.find().forEach(function(doc) {if(doc.number<0) b++;})
> b
3
> db.col_lab_2.find().forEach(function(doc) {if(doc.number!=0) c*=doc.number;})
> c
-1440
{ "_id" : ObjectId("5ba90752373e73b21e346f3a"), "firstName" : "Igor" }
{ "_id" : ObjectId("5ba90778373e73b21e346f3b"), "firstName" : "Andrey" }
{ "_id" : ObjectId("5ba9079a373e73b21e346f3c"), "firstName" : "Helen" }
{ "_id" : ObjectId("5ba907b9373e73b21e346f3d"), "firstName" : "NoName" }
{ "_id" : ObjectId("5ba907dc373e73b21e346f3e"), "firstName" : "Alexey" }
{ "_id" : ObjectId("5bcdf3afa7c67da00d165377"), "firstName" : "Natasha" }
> db.col_test_1.find(null, {creationDate:0, lastSess:0})
{ "_id" : ObjectId("5ba90752373e73b21e346f3a"), "index" : 1, "firstName" : "Igor", "lastName" : "Zolotarev", "age" : 21, "subjects" : [ "Math", "Physics" ] }
{ "_id" : ObjectId("5ba90778373e73b21e346f3b"), "index" : 1, "firstName" : "Andrey", "lastName" : "Zolotarev", "age" : 46, "subjects" : [ ] }
{ "_id" : ObjectId("5ba9079a373e73b21e346f3c"), "subjects" : [ "math", "art" ], "firstName" : "Helen", "lastName" : "Iriarte", "index" : 21 }
{ "_id" : ObjectId("5ba907b9373e73b21e346f3d"), "index" : 2, "firstName" : "NoName", "lastName" : "NoName", "age" : 0, "subjects" : [ ] }
{ "_id" : ObjectId("5ba907dc373e73b21e346f3e"), "index" : 3, "firstName" : "Alexey", "lastName" : "Maslov", "age" : 40, "subjects" : [ "Marketing" ] }
{ "_id" : ObjectId("5bcdf3afa7c67da00d165377"), "firstName" : "Natasha" }
> db.col_test_1.find(null, {firstName:1, _id:0})
{ "firstName" : "Igor" }
{ "firstName" : "Andrey" }
{ "firstName" : "Helen" }
{ "firstName" : "NoName" }
{ "firstName" : "Alexey" }
{ "firstName" : "Natasha" }
> db.col_test_1.find(null, {firstName:1}).sort({firstName:-1})
{ "_id" : ObjectId("5ba907b9373e73b21e346f3d"), "firstName" : "NoName" }
{ "_id" : ObjectId("5bcdf3afa7c67da00d165377"), "firstName" : "Natasha" }
{ "_id" : ObjectId("5ba90752373e73b21e346f3a"), "firstName" : "Igor" }
{ "_id" : ObjectId("5ba9079a373e73b21e346f3c"), "firstName" : "Helen" }
{ "_id" : ObjectId("5ba90778373e73b21e346f3b"), "firstName" : "Andrey" }
{ "_id" : ObjectId("5ba907dc373e73b21e346f3e"), "firstName" : "Alexey" }
> db.col_test_1.find(null, {firstName:1}).sort({firstName:1})
{ "_id" : ObjectId("5ba907dc373e73b21e346f3e"), "firstName" : "Alexey" }
{ "_id" : ObjectId("5ba90778373e73b21e346f3b"), "firstName" : "Andrey" }
{ "_id" : ObjectId("5ba9079a373e73b21e346f3c"), "firstName" : "Helen" }
{ "_id" : ObjectId("5ba90752373e73b21e346f3a"), "firstName" : "Igor" }
{ "_id" : ObjectId("5bcdf3afa7c67da00d165377"), "firstName" : "Natasha" }
{ "_id" : ObjectId("5ba907b9373e73b21e346f3d"), "firstName" : "NoName" }
db.col_test_1.find(null, {firstName:1}).sort({firstName:1}).limit(5)
{ "_id" : ObjectId("5ba907dc373e73b21e346f3e"), "firstName" : "Alexey" }
{ "_id" : ObjectId("5ba90778373e73b21e346f3b"), "firstName" : "Andrey" }
{ "_id" : ObjectId("5ba9079a373e73b21e346f3c"), "firstName" : "Helen" }
{ "_id" : ObjectId("5ba90752373e73b21e346f3a"), "firstName" : "Igor" }
{ "_id" : ObjectId("5bcdf3afa7c67da00d165377"), "firstName" : "Natasha" }
> db.col_test_1.find(null, {firstName:1}).sort({firstName:1}).skip(3)
{ "_id" : ObjectId("5ba90752373e73b21e346f3a"), "firstName" : "Igor" }
{ "_id" : ObjectId("5bcdf3afa7c67da00d165377"), "firstName" : "Natasha" }
{ "_id" : ObjectId("5ba907b9373e73b21e346f3d"), "firstName" : "NoName" }
> db.col_test_1.find(null, {firstName:1}).sort({firstName:1}).skip(3).limit(5)
{ "_id" : ObjectId("5ba90752373e73b21e346f3a"), "firstName" : "Igor" }
{ "_id" : ObjectId("5bcdf3afa7c67da00d165377"), "firstName" : "Natasha" }
{ "_id" : ObjectId("5ba907b9373e73b21e346f3d"), "firstName" : "NoName" }
> db.col_test_1.find(null, {firstName:1}).sort({firstName:1}).skip(3).count(1)
3
> db.col_test_1.find(null, {firstName:1}).sort({firstName:1}).skip(3).limit(5).count(1)
3
> db.col_test_1.find(null, {firstName:1}).sort({firstName:1}).limit(5).count(1)
5
> db.col_test_1.count()
6
> var b=0
> var a=0
> var c=1
> db.col_lab_2.find().forEach(function(doc) {if(doc.number>0) a+=doc.number;})
> a
18
> db.col_lab_2.find().forEach(function(doc) {if(doc.number<0) b++;})
> b
3
> db.col_lab_2.find().forEach(function(doc) {if(doc.number!=0) c*=doc.number;})
> c
-1440