1. 程式人生 > >淺嘗輒止MongoDB:操作(2)

淺嘗輒止MongoDB:操作(2)

目錄

        大部分摘自《MongoDB大資料處理權威指南》(第3版)。 

4. 更新資料

(1)update()
        在MongoDB中可以使用update()函式執行資料更新操作。該函式將接受3個主要引數:criteria、objNew和option。引數criteria可用於指定一個查詢,該查詢選擇將要更新的目標記錄。使用objNew引數指定更新資訊,也可以使用操作符來完成。引數option用於指定更新文件時的選項,它的可選值有upsert和multi。通過選項upsert可以指定該更新是否是upsert操作——它將告訴MongoDB,如果資料存在就更新,否則就建立資料。最後,通過選項multi可以指定是否應該更新所有匹配的文件,或者只更新第一個文件(預設行為)。

> db.media.update( { "Title" : "Matrix, The"}, {"Type" : "DVD", "Title" : "Matrix, The", "Released" : 1999, "Genre" : "Action"}, { upsert: true} );
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
>

        該例複寫了集合中的文件,併為之儲存更新後的值。注意,不帶$set操作符update()函式會移除任何忽略的鍵。如上面的語句執行後,Cast鍵已經被移除:

> db.media.find( { "Title" : "Matrix, The"});
{ "_id" : ObjectId("5bac6025fc59dd405445ee0d"), "Type" : "DVD", "Title" : "Matrix, The", "Released" : 1999, "Genre" : "Action" }
>

        修改單條記錄還可以使用updateOne函式,該函式與update的主要區別有兩點:

  1. 不移除忽略的鍵。
  2. 必須使用$set操作符。
> db.media.find( { "Title" : "Matrix, The"});
{ "_id" : ObjectId("5bac6025fc59dd405445ee0d"), "Type" : "DVD", "Title" : "Matrix, The", "Released" : 1999, "Genre" : "Action" }
> db.media.updateOne( { "Title" : "Matrix, The"}, {"Type" : "DVD"}, { upsert: true} );
2018-09-27T13:31:54.772+0800 E QUERY    [js] Error: the update operation document must contain atomic operators :
[email protected]
/mongo/shell/crud_api.js:542:1 @(shell):1:1 > db.media.updateOne( { "Title" : "Matrix, The"}, {$set:{"Type" : "DVD"}}, { upsert: true} ); { "acknowledged" : true, "matchedCount" : 1, "modifiedCount" : 0 } > db.media.updateOne( { "Title" : "Matrix, The"}, {$set:{"Type" : "DVD1"}}, { upsert: true} ); { "acknowledged" : true, "matchedCount" : 1, "modifiedCount" : 1 } > db.media.find( { "Title" : "Matrix, The"}); { "_id" : ObjectId("5bac6025fc59dd405445ee0d"), "Type" : "DVD1", "Title" : "Matrix, The", "Released" : 1999, "Genre" : "Action" } > db.media.updateOne( { "Title" : "Matrix, The"}, {$set:{"Type" : "DVD"}}, { upsert: true} ); { "acknowledged" : true, "matchedCount" : 1, "modifiedCount" : 1 } > db.media.find( { "Title" : "Matrix, The"}); { "_id" : ObjectId("5bac6025fc59dd405445ee0d"), "Type" : "DVD", "Title" : "Matrix, The", "Released" : 1999, "Genre" : "Action" } >

        如果要修改多條記錄也有兩種寫法:

db.media.updateMany( { "Title" : "Matrix, The"}, {$set:{"Type" : "DVD"}}, { upsert: true} );

        或者:

db.media.update( { "Title" : "Matrix, The"}, {$set:{"Type" : "DVD", "Title" : "Matrix, The", "Released" : 1999, "Genre" : "Action"}}, { upsert: true,multi:true} );

(2)save()
        可以使用save()命令執行upsert。如果不指定_id值,save()執行一個插入操作,否則執行upsert操作。

> db.products.save( { item: "book", qty: 40 } );
WriteResult({ "nInserted" : 1 })
> db.products.find();
{ "_id" : ObjectId("5bac6f41845a6b94a74d82f0"), "item" : "book", "qty" : 40 }
> db.products.save( { _id: 100, item: "water", qty: 30 } );
WriteResult({ "nMatched" : 0, "nUpserted" : 1, "nModified" : 0, "_id" : 100 })
> db.products.find();
{ "_id" : ObjectId("5bac6f41845a6b94a74d82f0"), "item" : "book", "qty" : 40 }
{ "_id" : 100, "item" : "water", "qty" : 30 }
> db.products.save( { _id : 100, item : "juice" } );
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
> db.products.find();
{ "_id" : ObjectId("5bac6f41845a6b94a74d82f0"), "item" : "book", "qty" : 40 }
{ "_id" : 100, "item" : "juice" }
>

(3)自動更新

  • $inc

        操作符$inc可以為指定的鍵執行原子更新操作,如果欄位存在,就將該值增加指定的增量,否則建立該鍵。

> manga = ( { "Type" : "Manga", "Title" : "One Piece", "Volumes" : 612, "Read" : 520 } );
{ "Type" : "Manga", "Title" : "One Piece", "Volumes" : 612, "Read" : 520 }
> db.media.insertOne(manga);
{
    "acknowledged" : true,
    "insertedId" : ObjectId("5bac706d845a6b94a74d82f1")
}
> db.media.updateOne ( { "Title" : "One Piece"}, {$inc: {"Read" : 4} } );
{ "acknowledged" : true, "matchedCount" : 1, "modifiedCount" : 1 }
> db.media.find ( { "Title" : "One Piece" } );
{ "_id" : ObjectId("5bac706d845a6b94a74d82f1"), "Type" : "Manga", "Title" : "One Piece", "Volumes" : 612, "Read" : 524 }
>
  • $set

        可以使用$set操作符將某些欄位設定為指定值。該操作符可以更新任何資料。

> db.media.update ( { "Title" : "Matrix, The" }, {$set : { Genre : "Sci-Fi" , Type : "DVD"} } );
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
>
  • $unset

        通過$unset操作符可以刪除指定的欄位。

> db.media.find( { "Title" : "Matrix, The"});
{ "_id" : ObjectId("5bac6025fc59dd405445ee0d"), "Type" : "DVD", "Title" : "Matrix, The", "Released" : 1999, "Genre" : "Sci-Fi" }
{ "_id" : ObjectId("5bac6c6c845a6b94a74d82ee"), "Title" : "Matrix, The" }
> db.media.updateOne ( {"Title": "Matrix, The"}, {$unset : { "Genre" : 1 } } );
{ "acknowledged" : true, "matchedCount" : 1, "modifiedCount" : 1 }
> db.media.find( { "Title" : "Matrix, The"});
{ "_id" : ObjectId("5bac6025fc59dd405445ee0d"), "Type" : "DVD", "Title" : "Matrix, The", "Released" : 1999 }
{ "_id" : ObjectId("5bac6c6c845a6b94a74d82ee"), "Title" : "Matrix, The" }
>
  • $push

        通過$push操作符可以在指定欄位中新增某個值。如果該欄位是個陣列,那麼該值將被新增到陣列中。如果該欄位尚不存在,那麼該欄位的值將被設定為陣列。如果該欄位存在,但不是陣列,那麼將會丟擲錯誤。

> db.media.updateOne ( {"ISBN" : "978-1-4842-1183-0"}, {$push: { Author : "Griffin, Stewie"} } );
{ "acknowledged" : true, "matchedCount" : 1, "modifiedCount" : 1 }
> db.media.updateOne ( {"ISBN" : "978-1-4842-1183-0"}, {$push: { Title : "This isn't an array"} } );
2018-09-27T14:20:46.314+0800 E QUERY    [js] WriteError: The field 'Title' must be an array but is of type string in document {_id: ObjectId('5baae32464e6602b766d94c0')} :
WriteError({
    "index" : 0,
    "code" : 2,
    "errmsg" : "The field 'Title' must be an array but is of type string in document {_id: ObjectId('5baae32464e6602b766d94c0')}",
    "op" : {
        "q" : {
            "ISBN" : "978-1-4842-1183-0"
        },
        "u" : {
            "$push" : {
                "Title" : "This isn't an array"
            }
        },
        "multi" : false,
        "upsert" : false
    }
})
[email protected]/mongo/shell/bulk_api.js:461:48
Bulk/[email protected]/mongo/shell/bulk_api.js:841:49
Bulk/[email protected]/mongo/shell/bulk_api.js:906:13
Bulk/[email protected]/mongo/shell/bulk_api.js:1150:21
[email protected]/mongo/shell/crud_api.js:572:17
@(shell):1:1
> db.media.find ( { "ISBN" : "978-1-4842-1183-0" } );
{ "_id" : ObjectId("5baae32464e6602b766d94c0"), "Type" : "Book", "Title" : "Definitive Guide to MongoDB 3rd ed., The", "ISBN" : "978-1-4842-1183-0", "Publisher" : "Apress", "Author" : [ "Hows, David", "Plugge, Eelco", "Membrey, Peter", "Hawkins, Tim", "Griffin, Stewie" ] }
{ "_id" : ObjectId("5baae32864e6602b766d94c1"), "Type" : "Book", "Title" : "Definitive Guide to MongoDB 3rd ed., The", "ISBN" : "978-1-4842-1183-0", "Publisher" : "Apress", "Author" : [ "Hows, David", "Plugge, Eelco", "Membrey, Peter", "Hawkins, Tim" ] }
>
  • $each

        給陣列新增幾個值:

> db.media.updateOne( { "ISBN" : "978-1-4842-1183-0" }, { $push: { Author : { $each:
... ["Griffin, Peter", "Griffin, Brian"] } } } );
{ "acknowledged" : true, "matchedCount" : 1, "modifiedCount" : 1 }
> db.media.findOne ( { "ISBN" : "978-1-4842-1183-0" } );
{
    "_id" : ObjectId("5baae32464e6602b766d94c0"),
    "Type" : "Book",
    "Title" : "Definitive Guide to MongoDB 3rd ed., The",
    "ISBN" : "978-1-4842-1183-0",
    "Publisher" : "Apress",
    "Author" : [
        "Hows, David",
        "Plugge, Eelco",
        "Membrey, Peter",
        "Hawkins, Tim",
        "Griffin, Stewie",
        "Griffin, Peter",
        "Griffin, Brian"
    ]
}
>

        在使用$each時還可以使用$slice操作符。通過這種方式可以限制$push操作符中陣列內元素的數量。$slice接受負數或0。使用負數將保證陣列中的最後n個元素會保留,而使用0則表示清空陣列。注意,操作符$slice必須是$push操作中的第一個修改操作符:

> db.media.updateOne( { "ISBN" : "978-1-4842-1183-0" }, { $push: { Author : { $each:
... ["Griffin, Meg", "Griffin, Louis"], $slice: -2 } } } );
{ "acknowledged" : true, "matchedCount" : 1, "modifiedCount" : 1 }
> db.media.findOne ( { "ISBN" : "978-1-4842-1183-0" } );
{
    "_id" : ObjectId("5baae32464e6602b766d94c0"),
    "Type" : "Book",
    "Title" : "Definitive Guide to MongoDB 3rd ed., The",
    "ISBN" : "978-1-4842-1183-0",
    "Publisher" : "Apress",
    "Author" : [
        "Griffin, Meg",
        "Griffin, Louis"
    ]
}
>
  • $addToSet

        操作符$addToSet是另一個可用於向陣列中新增資料的命令。不過,只有資料不存在的時候,該操作符才能將資料新增到陣列中。它的工作方式與$push不同。

> db.media.updateOne( { "ISBN" : "978-1-4842-1183-0" }, {$addToSet : { Author : "Griffin, Brian" } } );
{ "acknowledged" : true, "matchedCount" : 1, "modifiedCount" : 1 }
> db.media.findOne ( { "ISBN" : "978-1-4842-1183-0" } );
{
    "_id" : ObjectId("5baae32464e6602b766d94c0"),
    "Type" : "Book",
    "Title" : "Definitive Guide to MongoDB 3rd ed., The",
    "ISBN" : "978-1-4842-1183-0",
    "Publisher" : "Apress",
    "Author" : [
        "Griffin, Meg",
        "Griffin, Louis",
        "Griffin, Brian"
    ]
}
>

(4)從陣列中刪除元素

  • $pop

        刪除陣列中第一個或最後一個元素:

> db.media.updateOne( { "ISBN" : "978-1-4842-1183-0" }, {$pop : {Author : 1 } } );
{ "acknowledged" : true, "matchedCount" : 1, "modifiedCount" : 1 }
> db.media.findOne ( { "ISBN" : "978-1-4842-1183-0" } );
{
    "_id" : ObjectId("5baae32464e6602b766d94c0"),
    "Type" : "Book",
    "Title" : "Definitive Guide to MongoDB 3rd ed., The",
    "ISBN" : "978-1-4842-1183-0",
    "Publisher" : "Apress",
    "Author" : [
        "Griffin, Meg",
        "Griffin, Louis"
    ]
}
> db.media.updateOne( { "ISBN" : "978-1-4842-1183-0" }, {$pop : {Author : -1 } } );
{ "acknowledged" : true, "matchedCount" : 1, "modifiedCount" : 1 }
> db.media.findOne ( { "ISBN" : "978-1-4842-1183-0" } );
{
    "_id" : ObjectId("5baae32464e6602b766d94c0"),
    "Type" : "Book",
    "Title" : "Definitive Guide to MongoDB 3rd ed., The",
    "ISBN" : "978-1-4842-1183-0",
    "Publisher" : "Apress",
    "Author" : [
        "Griffin, Louis"
    ]
}
>
  • $pull

        刪除所有指定值:

> db.media.updateOne ( {"ISBN" : "978-1-4842-1183-0"}, {$push: { Author : "Griffin, Stewie"} } );
{ "acknowledged" : true, "matchedCount" : 1, "modifiedCount" : 1 }
> db.media.findOne ( { "ISBN" : "978-1-4842-1183-0" } );
{
    "_id" : ObjectId("5baae32464e6602b766d94c0"),
    "Type" : "Book",
    "Title" : "Definitive Guide to MongoDB 3rd ed., The",
    "ISBN" : "978-1-4842-1183-0",
    "Publisher" : "Apress",
    "Author" : [
        "Griffin, Louis",
        "Griffin, Stewie"
    ]
}
> db.media.updateOne ( {"ISBN" : "978-1-4842-1183-0"}, {$pull : { Author : "Griffin, Stewie" } } );
{ "acknowledged" : true, "matchedCount" : 1, "modifiedCount" : 1 }
> db.media.findOne ( { "ISBN" : "978-1-4842-1183-0" } );
{
    "_id" : ObjectId("5baae32464e6602b766d94c0"),
    "Type" : "Book",
    "Title" : "Definitive Guide to MongoDB 3rd ed., The",
    "ISBN" : "978-1-4842-1183-0",
    "Publisher" : "Apress",
    "Author" : [
        "Griffin, Louis"
    ]
}
>
  • $pullAll

        刪除陣列中的多個元素:

> db.media.updateOne( { "ISBN" : "978-1-4842-1183-0"}, {$pullAll : { Author : ["Griffin, Louis","Griffin, Peter","Griffin, Brian"] } } );
{ "acknowledged" : true, "matchedCount" : 1, "modifiedCount" : 1 }
> db.media.findOne ( { "ISBN" : "978-1-4842-1183-0" } );
{
    "_id" : ObjectId("5baae32464e6602b766d94c0"),
    "Type" : "Book",
    "Title" : "Definitive Guide to MongoDB 3rd ed., The",
    "ISBN" : "978-1-4842-1183-0",
    "Publisher" : "Apress",
    "Author" : [ ]
}
>

(5)指定匹配陣列的位置
        可以在查詢中使用$操作符指定查詢中匹配陣列元素的位置。該操作符可用於在搜尋到一個數組元素之後,對它進行資料操作。

> db.media.updateOne( { "Artist" : "Nirvana" }, {$addToSet : { Tracklist : {"Track" : 2,"Title": "Been a Son", "Length":"2:23"} } } );
{ "acknowledged" : true, "matchedCount" : 1, "modifiedCount" : 1 }
> db.media.findOne ( { "Tracklist.Title" : "Been a Son"});
{
    "_id" : ObjectId("5baae67464e6602b766d94c3"),
    "Type" : "CD",
    "Artist" : "Nirvana",
    "Title" : "Nevermind",
    "Tracklist" : [
        {
            "Track" : 2,
            "Title" : "Been a Son",
            "Length" : "2:23"
        }
    ]
}
> db.media.updateOne( { "Tracklist.Title" : "Been a Son"}, {$inc:{"Tracklist.$.Track" : 1} } );
{ "acknowledged" : true, "matchedCount" : 1, "modifiedCount" : 1 }
> db.media.findOne ( { "Tracklist.Title" : "Been a Son"});
{
    "_id" : ObjectId("5baae67464e6602b766d94c3"),
    "Type" : "CD",
    "Artist" : "Nirvana",
    "Title" : "Nevermind",
    "Tracklist" : [
        {
            "Track" : 3,
            "Title" : "Been a Son",
            "Length" : "2:23"
        }
    ]
}
>

(6)原子操作
        MongoDB支援對單個文件的原子操作,不支援在單個操作中以原子方式更新多個文件。如果一組操作滿足下面的條件,那就可以稱它們為原子操作:

  • 其它程序無法獲得修改結果,除非整租操作都已完成。
  • 如果其中一個操作失敗,整個原子操作都將失敗,並全部回滾,資料將被恢復至執行原子操作之前的狀態。

        執行原子操作時的標準行為是鎖定資料,不允許其它查詢訪問,但MongoDB不支援鎖或複雜的事務。MongoDB包含的幾種更新操作都可以原子操作的方式更新資料:

  • $set:設定特定值。
  • $unset:刪除特定值。
  • $inc:將某個值增大特定的量。
  • $push:向陣列中新增值。
  • $pull:從現有陣列中刪除單個值。
  • $pullAll:從現有陣列中刪多個值。

        使用Update if Current方法
        另一個更新資料的策略是使用Update if Current(如果資料目前仍未改變就更新)方法。該方法有3個步驟,所有步驟都是以原子的方式完成:

  1. 從文件中取得物件。
  2. 在本地修改物件。
  3. 傳送更新請求更新物件值,假定當前值仍然匹配之前取得的值。

        該方法本質上是一種樂觀鎖定的實現。為了避免併發情況下的ABA問題,可以使用下面的方法:

  • 在更新的查詢表示式中使用完整的物件,而不是隻使用_id和comments.by欄位。
  • 使用$set更新重要的欄位。即使其它欄位已經改變,也不會受該欄位的影響。
  • 在物件中新增一個版本變數,並在每次更新時增加它的值。
  • 如果可能,使用$操作符,而不是Update-if-Current序列操作。

        還可以通過執行findAndModify命令來實現對文件的原子操作。該命令將修改並返回文件。它接受3個主要操作符:<query>用於指定目標文件;<sort>用於對多個匹配文件進行排序;<operations>用於指定希望執行的操作。例如:

> db.media.findAndModify( { "Title" : "One Piece",sort:{"Title": -1}, remove: true} );
{
    "_id" : ObjectId("5bab30521062c31f5bdf664b"),
    "Type" : "DVD",
    "Title" : "Toy Story 3",
    "Released" : 2010
}
>

        這段程式碼返回匹配搜尋條件的文件,找到並刪除Title為'One Piece'的第一個文件。下面的例子將修改文件而不是刪除:

> db.media.findAndModify( { query: { "ISBN" : "978-1-4842-1183-0" }, sort: {"Title":-1},update: {$set: {"Title" : " Different Title"} } } );
{
    "_id" : ObjectId("5baae32464e6602b766d94c0"),
    "Type" : "Book",
    "Title" : "Definitive Guide to MongoDB 3rd ed., The",
    "ISBN" : "978-1-4842-1183-0",
    "Publisher" : "Apress",
    "Author" : [ ]
}
>

        如果希望返回更新後的文件,可以在查詢後新增new操作符:

> db.media.findAndModify( { query: { "ISBN" : "978-1-4842-1183-0" }, sort: {"Title":-1},update: {$set: {"Title" : " Different Title"} }, new:true } );
{
    "_id" : ObjectId("5baae32864e6602b766d94c1"),
    "Type" : "Book",
    "Title" : " Different Title",
    "ISBN" : "978-1-4842-1183-0",
    "Publisher" : "Apress",
    "Author" : [
        "Hows, David",
        "Plugge, Eelco",
        "Membrey, Peter",
        "Hawkins, Tim"
    ]
}
>

        該命令中可以使用任何修改操作符,而不只是$set。

相關推薦

淺嘗輒止MongoDB操作2

目錄         大部分摘自《MongoDB大資料處理權威指南》(第3版)。  4. 更新資料 (1)update()         在MongoDB中可以使用update()函式執行資料更新操作。該函式將接受3個主要引數:criteria、objNew和op

淺嘗輒止MongoDB管理2

目錄 五、監控 四、驗證與修復         以下是一些資料已損壞的跡象: 資料庫伺服器無法啟動,表示資料檔案已損壞。 在伺服器日誌檔案中發現asserts或使用db.serverStatus()

淺嘗輒止MongoDB管理1

目錄         MongoDB和SQL資料庫之間的主要區別是: 不需要在伺服器上建立資料庫、集合或欄位,因為MongoDB將在訪問它們時動態建立這些元素。 MongoDB中的所有物件和元素名稱

EntityFramework Core筆記表結構及數據操作2

IV totable prot table AS lec ext lib models 1. 表結構操作 1.1 表名   Data Annotations: using System.ComponentModel.DataAnnotations.Schema;

小白學 Python 資料分析6Pandas 基礎操作2資料選擇

人生苦短,我用 Python 前文傳送門: 小白學 Python 資料分析(1):資料分析基礎 小白學 Python 資料分析(2):Pandas (一)概述 小白學 Python 資料分析(3):Pandas (二)資料結構 Series 小白學 Python 資料分析(4):Pandas (三)資

Hibernate的增刪改查操作2

rac result jlist static 面向 原生 comm public set 一、在Hibernate中使用原生SQL語句 sql語句面向的是數據庫,所以sql語句中對應的不再是bean了,比如sql="select * from user" 在hql中

SpringMVC基本操作2

正常 esp 模型 over edi 錯誤 handle 之前 表現 1.)使用 POJO 對象綁定請求參數值 ? Spring MVC 會按請求參數名和 POJO 屬性名進行自動匹 配,自動為該對象填充屬性值。支持級聯屬性。 如:dept.deptId、dept.addr

27. Python對Mysql的操作2

python mysql1.遊標遊標是系統為用戶開設的一個數據緩沖區,存放SQL語句的執行結果用戶可以用SQL語句逐一從遊標中獲取記錄,並賦給主變量,交由python進一步處理,一組主變量一次只能存放一條記錄僅使用主變量並不能完全滿足SQL語句向應用程序輸出數據的要求遊標提供了一種對從表中檢索出的數據進行操作

MySQL數據庫操作2基本操作

大於 ase 存在 delete div .... desc 搜索 查看數據庫 創建數據庫:CREATE DATABASE [IF NOT EXISTS] 庫名例子:CREATE DATABASE `mydb`;CREATE DATABASE IF NOT EXISTS `

3-MongoDB 查詢

簡單 gte ted 分享圖片 string font 投影 binary ava 一、簡介 MongoDB提供了db.collection.find() 方法可以實現根據條件查詢和指定使用投影運算符返回的字段省略此參數返回匹配文檔中的所有字段。 二.db.co

MySQL常用操作2MySQL用戶管理、常用sql語句、 MySQL數據庫備份恢復

MySQL用戶管理 MySQL用戶管理創建一個普通用戶並且授權1.grant all on *.* to 'user1' identified by 'passwd';grant all on *.* to 'user1' iden

matlab基本操作2

sin res 9.png 一個 nbsp 分享圖片 輸出 .com 返回 %求特征值和特征向量 x=0:0.01:50; A=[1 2 3 12;4 5 6 11;7 8 9 10;2 3 4 5]; B=[2 7;3 4]; eig(A); % ans = % %

MATLAB編程與應用系列-第2章 數組及矩陣的創建及操作2

示例 例如 matrix 6.2 由於 變量 com 語法 2.4 本系列教程來源於出版設計《基於MATLAB編程基礎與典型應用書籍》,如涉及版權問題,請聯系:[email protected]。 出版社:人民郵電出版社, 頁數:525。 本系列教程目前基於MATLABR20

javaweb學習筆記十六JDBC2

批處理 當需要向資料庫傳送一批SQL語句執行時,應避免向資料庫一條條的傳送執行,而應採用JDBC的批處理機制,以提升執行效率。 實現批處理有兩種方式: ①Statement.addBatch(sql) :新增批處理命令。 優點:可以向資料庫傳送多條不同的SQL語句。 缺點:S

javaweb學習筆記十二JSP2

jsp(2) 目錄 jsp(2) 1.Jsp指令 1.1 include指令 1.2 page指令 1.3 taglib指令 2. Jsp的隱式物件 2.1 out物件 2.2 pageContext物件 1.J

javaweb學習筆記JavaScript2

目錄 1.BOM 1.1window物件 1.2history物件 1.3location物件 2. DOM 2.1dom節點及獲取 2.2Event 1.BOM 1.1window物件 一般來說,Window 物件的方法都是對瀏覽器視窗或框架進行某種

Django ORM相關操作2

今天就講講關於雙下劃線的操作,這是第二篇關於orm相關操作的文章,還想看請往上翻第一篇。   # -*- coding: utf-8 -*- # @Time : 2018/11/15 19:26 # @Author : lh # @Email : .com # @F

MongoDB學習筆記2

MongoDB 建立資料庫 語法 MongoDB 建立資料庫的語法格式如下: use DATABASE_NAME 如果資料庫不存在,則建立資料庫,否則切換到指定資料庫。 例項 以下例項我們建立了資料庫 runoob: > use runoob switched to db

Robot Framework - 入門與操作2

04- 建立測試庫--基礎概念 Robot Framework 實際的測試能力是由測試庫提供的。 ***** 支援的程式語言 Robot Framework 自身是用 Python 編寫的,能使用 Python 擴充套件測試庫。 如果在 Jython 執行Robot Frame

第11章 拾遺4IPv62_給計算機配置IPv6地址

4. 給計算機配置IPv6地址 4.1 無狀態自動配置IPv6地址 (1)網路拓撲   ①無狀態地址自動配置是指不需要DHCP伺服器進行管理,由客戶端向路由器傳送字首請求(RS)詢問其所在網段。路由器收到RS後,會發送字首公告訊息(RA),客戶端根據網路RA並自己的MAC地址計算出