Whatever message this page gives is out now! Go check it out!
component {
this.name = "mongotests";
this.serialization.preservecaseforstructkey=true
this.enableNullSupport=true
this.cosmosconfig = deserializejson(fileread(expandPath(".\cosmosconfig.json"))) //storing credentials outside web root
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
}
}
}{
"host": "host:port",
"username": "username",
"password": "password",
"replicaSet": "globaldb"
}<cfscript>
// Retrieve database
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/>")
// Insert many documents
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"
}
}
])
//count number of documents in the collection
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>