ColdFusion と Azure Cosmos DB

Cosmos DBは、次のような機能のコアセットを備えた、分散データベースエンジンです。

  • データベースを世界中に分散させる機能
  • ストレージとスループットの両方をスケールする機能
  • エンタープライズグレードのセキュリティ機能を備えながら低遅延

Cosmos DB は、データを既に使用している形式に再成形できます。データモデルを作成し、多くの Cosmos DB API のいずれかを使用して、モデルを公開できます。

詳しくは、Azure Cosmos DB を参照してください。

ColdFusion との統合

Application.cfc

component {
this.name = "mongotests";
this.serialization.preservecaseforstructkey=true
this.enableNullSupport=true
this.cosmosconfig = deserializejson(fileread(expandPath(".\cosmosconfig.json"))) // web ルートの外部に資格情報を格納
this.datasources = {
"local"= {
type="mongodb"
},
"cosmos"= {
type="mongodb",
host="mongodb://" & this.cosmosconfig.host & "/?ssl=true&retrywrites=false",
"init": true,
"username": this.cosmosconfig.username,
"password": this.cosmosconfig.password
}
}
}
component { this.name = "mongotests"; this.serialization.preservecaseforstructkey=true this.enableNullSupport=true this.cosmosconfig = deserializejson(fileread(expandPath(".\cosmosconfig.json"))) // web ルートの外部に資格情報を格納 this.datasources = { "local"= { type="mongodb" }, "cosmos"= { type="mongodb", host="mongodb://" & this.cosmosconfig.host & "/?ssl=true&retrywrites=false", "init": true, "username": this.cosmosconfig.username, "password": this.cosmosconfig.password } } }
component { 
    this.name = "mongotests"; 
    this.serialization.preservecaseforstructkey=true 
    this.enableNullSupport=true 
    this.cosmosconfig = deserializejson(fileread(expandPath(".\cosmosconfig.json"))) // web ルートの外部に資格情報を格納 
    this.datasources = { 
        "local"= { 
            type="mongodb" 
        }, 
        "cosmos"= { 
            type="mongodb", 
            host="mongodb://" & this.cosmosconfig.host & "/?ssl=true&retrywrites=false", 
            "init": true, 
            "username": this.cosmosconfig.username, 
            "password": this.cosmosconfig.password 
        } 
    } 
}

cosmosconfig.json

{
"host": "host:port",
"username": "username",
"password": "password",
"replicaSet": "globaldb"
}
{ "host": "host:port", "username": "username", "password": "password", "replicaSet": "globaldb" }
{ 
    "host": "host:port", 
    "username": "username", 
    "password": "password", 
    "replicaSet": "globaldb" 
}

demo.cfm

<cfscript>
// データベースを取得
db = getmongoservice(&quot;cosmos&quot;).db(&quot;mydb&quot;)
collection = db.collection
collection.drop()
writeOutput(&quot;number of documents in the collection: <b>&quot; & collection.count() & &quot; </b><br/>&quot;)
writeOutput(&quot;<b> Insert a document </b><br/>&quot;)
// 多数のドキュメントを挿入
res = collection.insertMany([
{
enrollno: &quot;1001&quot;,
name: &quot;John Doe&quot;,
college: &quot;Any college&quot;,
course: {
courseName: &quot;Any course&quot;,
duration: &quot;4 Years&quot;
},
address: {
city: &quot;Any city&quot;,
state: &quot;Any state&quot;,
country: &quot;Any country&quot;
}
},
{
enrollno: &quot;1002&quot;,
name: &quot;Jane Doe&quot;,
college: &quot;Some college&quot;,
course: {
courseName: &quot;Some course&quot;,
duration: &quot;4 Years&quot;
},
address: {
city: &quot;Some city&quot;,
state: &quot;Some state&quot;,
country: &quot;Some country&quot;
}
}
])
// コレクション内のドキュメントの数をカウント
writeOutput(&quot;number of documents in the collection: <b>&quot; & collection.count() & &quot; </b><br/>&quot;)
writeOutput(&quot;<b> Delete a document </b><br/>&quot;)
collection.deleteOne({name: MongoRegExp(&quot;Rushikesh Vekariya&quot;,&quot;i&quot;)})
writeOutput(&quot;number of documents in the collection: <b>&quot; & collection.count() & &quot; </b><br/>&quot;)
</cfscript>
<cfscript> // データベースを取得 db = getmongoservice(&quot;cosmos&quot;).db(&quot;mydb&quot;) collection = db.collection collection.drop() writeOutput(&quot;number of documents in the collection: <b>&quot; & collection.count() & &quot; </b><br/>&quot;) writeOutput(&quot;<b> Insert a document </b><br/>&quot;) // 多数のドキュメントを挿入 res = collection.insertMany([ { enrollno: &quot;1001&quot;, name: &quot;John Doe&quot;, college: &quot;Any college&quot;, course: { courseName: &quot;Any course&quot;, duration: &quot;4 Years&quot; }, address: { city: &quot;Any city&quot;, state: &quot;Any state&quot;, country: &quot;Any country&quot; } }, { enrollno: &quot;1002&quot;, name: &quot;Jane Doe&quot;, college: &quot;Some college&quot;, course: { courseName: &quot;Some course&quot;, duration: &quot;4 Years&quot; }, address: { city: &quot;Some city&quot;, state: &quot;Some state&quot;, country: &quot;Some country&quot; } } ]) // コレクション内のドキュメントの数をカウント writeOutput(&quot;number of documents in the collection: <b>&quot; & collection.count() & &quot; </b><br/>&quot;) writeOutput(&quot;<b> Delete a document </b><br/>&quot;) collection.deleteOne({name: MongoRegExp(&quot;Rushikesh Vekariya&quot;,&quot;i&quot;)}) writeOutput(&quot;number of documents in the collection: <b>&quot; & collection.count() & &quot; </b><br/>&quot;) </cfscript>
<cfscript> 
    // データベースを取得 
    db = getmongoservice(&quot;cosmos&quot;).db(&quot;mydb&quot;) 
    collection = db.collection 
    collection.drop() 
    writeOutput(&quot;number of documents in the collection: <b>&quot; & collection.count() & &quot; </b><br/>&quot;) 
    writeOutput(&quot;<b> Insert a document </b><br/>&quot;) 
     
    // 多数のドキュメントを挿入 
    res = collection.insertMany([ 
    { 
        enrollno: &quot;1001&quot;, 
        name: &quot;John Doe&quot;, 
        college: &quot;Any college&quot;, 
        course: { 
            courseName: &quot;Any course&quot;, 
            duration: &quot;4 Years&quot; 
        }, 
        address: { 
            city: &quot;Any city&quot;, 
            state: &quot;Any state&quot;, 
            country: &quot;Any country&quot; 
        } 
    }, 
    { 
        enrollno: &quot;1002&quot;, 
        name: &quot;Jane Doe&quot;, 
        college: &quot;Some college&quot;, 
        course: { 
            courseName: &quot;Some course&quot;, 
            duration: &quot;4 Years&quot; 
        }, 
        address: { 
            city: &quot;Some city&quot;, 
            state: &quot;Some state&quot;, 
            country: &quot;Some country&quot; 
    } 
    } 
    ]) 
 
    // コレクション内のドキュメントの数をカウント 
    writeOutput(&quot;number of documents in the collection: <b>&quot; & collection.count() & &quot; </b><br/>&quot;) 
    writeOutput(&quot;<b> Delete a document </b><br/>&quot;) 
    collection.deleteOne({name: MongoRegExp(&quot;Rushikesh Vekariya&quot;,&quot;i&quot;)}) 
    writeOutput(&quot;number of documents in the collection: <b>&quot; & collection.count() & &quot; </b><br/>&quot;) 
</cfscript>

類似の記事

ヘルプをすばやく簡単に入手

新規ユーザーの場合