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