Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
17
Добавлен:
29.10.2021
Размер:
6.89 Кб
Скачать
> db.col_test_1.find()
{ "_id" : ObjectId("5ba90752373e73b21e346f3a"), "index" : 1, "firstName" : "Igor", "lastName" : "Zolotarev", "age" : 21, "subjects" : [ "Math", "Physics" ], "creationDate" : ISODate("2018-09-24T15:48:34.103Z") }
{ "_id" : ObjectId("5ba90778373e73b21e346f3b"), "index" : 1, "firstName" : "Andrey", "lastName" : "Zolotarev", "age" : 46, "subjects" : [ ], "creationDate" : ISODate("2018-09-24T15:49:12.692Z") }
{ "_id" : ObjectId("5ba9079a373e73b21e346f3c"), "index" : 1, "firstName" : "Helen", "lastName" : "Helen", "age" : 11, "subjects" : [ "Programming" ], "creationDate" : ISODate("2018-09-24T15:49:46.338Z") }
{ "_id" : ObjectId("5ba907b9373e73b21e346f3d"), "index" : 2, "firstName" : "NoName", "lastName" : "NoName", "age" : 0, "subjects" : [ ], "creationDate" : ISODate("2018-09-24T15:50:17.639Z") }
{ "_id" : ObjectId("5ba907dc373e73b21e346f3e"), "index" : 3, "firstName" : "Alexey", "lastName" : "Maslov", "age" : 40, "subjects" : [ "Marketing" ], "creationDate" : ISODate("2018-09-24T15:50:52.877Z") }

> db.col_test_1.update({firstName : "Helen"}, {subjects:["math"]})
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })

> db.col_test_1.find()
{ "_id" : ObjectId("5ba90752373e73b21e346f3a"), "index" : 1, "firstName" : "Igor", "lastName" : "Zolotarev", "age" : 21, "subjects" : [ "Math", "Physics" ], "creationDate" : ISODate("2018-09-24T15:48:34.103Z") }
{ "_id" : ObjectId("5ba90778373e73b21e346f3b"), "index" : 1, "firstName" : "Andrey", "lastName" : "Zolotarev", "age" : 46, "subjects" : [ ], "creationDate" : ISODate("2018-09-24T15:49:12.692Z") }
{ "_id" : ObjectId("5ba9079a373e73b21e346f3c"), "subjects" : [ "math" ] }
{ "_id" : ObjectId("5ba907b9373e73b21e346f3d"), "index" : 2, "firstName" : "NoName", "lastName" : "NoName", "age" : 0, "subjects" : [ ], "creationDate" : ISODate("2018-09-24T15:50:17.639Z") }
{ "_id" : ObjectId("5ba907dc373e73b21e346f3e"), "index" : 3, "firstName" : "Alexey", "lastName" : "Maslov", "age" : 40, "subjects" : [ "Marketing" ], "creationDate" : ISODate("2018-09-24T15:50:52.877Z") }

> db.col_test_1.update({_id:ObjectId("5ba9079a373e73b21e346f3c")},{$set: {firstName: "Helen", lastName: "Iriarte", index: 4}})
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })

> db.col_test_1.find()
{ "_id" : ObjectId("5ba90752373e73b21e346f3a"), "index" : 1, "firstName" : "Igor", "lastName" : "Zolotarev", "age" : 21, "subjects" : [ "Math", "Physics" ], "creationDate" : ISODate("2018-09-24T15:48:34.103Z") }
{ "_id" : ObjectId("5ba90778373e73b21e346f3b"), "index" : 1, "firstName" : "Andrey", "lastName" : "Zolotarev", "age" : 46, "subjects" : [ ], "creationDate" : ISODate("2018-09-24T15:49:12.692Z") }
{ "_id" : ObjectId("5ba9079a373e73b21e346f3c"), "subjects" : [ "math" ], "firstName" : "Helen", "lastName" : "Iriarte", "index" : 4 }
{ "_id" : ObjectId("5ba907b9373e73b21e346f3d"), "index" : 2, "firstName" : "NoName", "lastName" : "NoName", "age" : 0, "subjects" : [ ], "creationDate" : ISODate("2018-09-24T15:50:17.639Z") }
{ "_id" : ObjectId("5ba907dc373e73b21e346f3e"), "index" : 3, "firstName" : "Alexey", "lastName" : "Maslov", "age" : 40, "subjects" : [ "Marketing" ], "creationDate" : ISODate("2018-09-24T15:50:52.877Z") }

> db.col_test_1.update({_id:ObjectId("5ba9079a373e73b21e346f3c")},{$inc: {index: 3}})
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })

> db.col_test_1.find({_id:ObjectId("5ba9079a373e73b21e346f3c")})
{ "_id" : ObjectId("5ba9079a373e73b21e346f3c"), "subjects" : [ "math" ], "firstName" : "Helen", "lastName" : "Iriarte", "index" : 7 }

> db.col_test_1.update({_id:ObjectId("5ba9079a373e73b21e346f3c")},{$push: {subjects: "art"}})
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })

> db.col_test_1.find({_id:ObjectId("5ba9079a373e73b21e346f3c")})
{ "_id" : ObjectId("5ba9079a373e73b21e346f3c"), "subjects" : [ "math", "art" ], "firstName" : "Helen", "lastName" : "Iriarte", "index" : 7 }

> db.col_test_1.update({_id:ObjectId("5ba9079a373e73b21e346f3c")},{$mul: {index: 3}})
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })

> db.col_test_1.find({_id:ObjectId("5ba9079a373e73b21e346f3c")})
{ "_id" : ObjectId("5ba9079a373e73b21e346f3c"), "subjects" : [ "math", "art" ], "firstName" : "Helen", "lastName" : "Iriarte", "index" : 21 }

> db.col_test_1.update({},{$inc: {lastSess: 1}}, true, true)
WriteResult({ "nMatched" : 5, "nUpserted" : 0, "nModified" : 5 })

> db.col_test_1.find()
{ "_id" : ObjectId("5ba90752373e73b21e346f3a"), "index" : 1, "firstName" : "Igor", "lastName" : "Zolotarev", "age" : 21, "subjects" : [ "Math", "Physics" ], "creationDate" : ISODate("2018-09-24T15:48:34.103Z"), "lastSess" : 4 }
{ "_id" : ObjectId("5ba90778373e73b21e346f3b"), "index" : 1, "firstName" : "Andrey", "lastName" : "Zolotarev", "age" : 46, "subjects" : [ ], "creationDate" : ISODate("2018-09-24T15:49:12.692Z"), "lastSess" : 1 }
{ "_id" : ObjectId("5ba9079a373e73b21e346f3c"), "subjects" : [ "math", "art" ], "firstName" : "Helen", "lastName" : "Iriarte", "index" : 21, "lastSess" : 4 }
{ "_id" : ObjectId("5ba907b9373e73b21e346f3d"), "index" : 2, "firstName" : "NoName", "lastName" : "NoName", "age" : 0, "subjects" : [ ], "creationDate" : ISODate("2018-09-24T15:50:17.639Z"), "lastSess" : 1 }
{ "_id" : ObjectId("5ba907dc373e73b21e346f3e"), "index" : 3, "firstName" : "Alexey", "lastName" : "Maslov", "age" : 40, "subjects" : [ "Marketing" ], "creationDate" : ISODate("2018-09-24T15:50:52.877Z"), "lastSess" : 1 }

> db.col_test_1.update({firstName : "Natasha"},{$inc: {lastSess: 1}}, true)
WriteResult({
"nMatched" : 0,
"nUpserted" : 1,
"nModified" : 0,
"_id" : ObjectId("5bcdf3afa7c67da00d165377")
})
> db.col_test_1.find()
{ "_id" : ObjectId("5ba90752373e73b21e346f3a"), "index" : 1, "firstName" : "Igor", "lastName" : "Zolotarev", "age" : 21, "subjects" : [ "Math", "Physics" ], "creationDate" : ISODate("2018-09-24T15:48:34.103Z"), "lastSess" : 4 }
{ "_id" : ObjectId("5ba90778373e73b21e346f3b"), "index" : 1, "firstName" : "Andrey", "lastName" : "Zolotarev", "age" : 46, "subjects" : [ ], "creationDate" : ISODate("2018-09-24T15:49:12.692Z"), "lastSess" : 1 }
{ "_id" : ObjectId("5ba9079a373e73b21e346f3c"), "subjects" : [ "math", "art" ], "firstName" : "Helen", "lastName" : "Iriarte", "index" : 21, "lastSess" : 4 }
{ "_id" : ObjectId("5ba907b9373e73b21e346f3d"), "index" : 2, "firstName" : "NoName", "lastName" : "NoName", "age" : 0, "subjects" : [ ], "creationDate" : ISODate("2018-09-24T15:50:17.639Z"), "lastSess" : 1 }
{ "_id" : ObjectId("5ba907dc373e73b21e346f3e"), "index" : 3, "firstName" : "Alexey", "lastName" : "Maslov", "age" : 40, "subjects" : [ "Marketing" ], "creationDate" : ISODate("2018-09-24T15:50:52.877Z"), "lastSess" : 1 }
{ "_id" : ObjectId("5bcdf3afa7c67da00d165377"), "firstName" : "Natasha", "lastSess" : 1 }

Соседние файлы в папке Готовые лабы