Whatever message this page gives is out now! Go check it out!
fsObject= getCloudService("fsCred", "fsConf")component{
this.name ="FireStore_Test"
this.serialization.preservecaseforstructkey=true
this.enableNullSupport=true
void function onApplicationStart(){
application.gcpCred = {
projectId : "my-gcp-project",
credentialJsonFilePath : "C:\path\Gcp_Firestore\my-gcp-project-250541665619.json"
};
application.gcpConf = {
serviceName : "FIRESTORE"
};
}
}fsObject = getCloudService(application.fsCred, application.fsConf)<cfscript>
// define the credential and the configuration aliases in the ColdFusion Admin
fsObject=getCloudService("fsCred","fsConf")
// code below.
...........
</cfscript><cfscript>
// Using credential alias and struct for service config
fsConf = {
"alias":"gcpConf",
"serviceName" : "GCP_STORAGE",
"clientOverrideConfig":{
"retryPolicy":{
"numRetries":4
}
},
"httpClientConfig":{
"maxConnections":50
}
}
fsObject= getCloudService("fsCred", fsConf)
// code below
.....................
</cfscript><cfscript>
// Using config alias and struct for service credentials
// GCP credentials
fsCreds={
"vendorName":"GCP",
"alias": "fsCred",
"projectId":"1234",
" credentialJsonFilePath ": "file path"
}
fsObject= getCloudService(fsCreds, "fsConf")
// code below
.....................................
</cfscript><cfscript>
// Using Structs for both cloud credential and config
fsCreds={
"vendorName":"GCP",
"alias": "fsCred",
"projectId":"1234",
" credentialJsonFilePath ": "file path"
}
fsConf = {
"alias":"fsConf",
"serviceName" : "firestore",
"clientOverrideConfig":{
"retryPolicy":{
"numRetries":4
}
},
"httpClientConfig":{
"maxConnections":50
}
}
fsObject= getCloudService(fsCreds, fsConf)
// code below
...................................................................
</cfscript>add cloudcredential alias=FirestoreCred credentialJSONFilePath=<location to cred.json> projectId=proj-id vendorName=GCPset cloudcredential firestoreCred projectId=proj-idget cloudcredential firestoreCred credentialJSONFilePathshow cloudcredential firestoreCredexport cloudcredential ccd.jsondelete cloudcredential firestoreCredimport cloudcredential ccd.jsonadd cloudconfiguration alias=firestore1 keepAliveTime=1m keepAliveTimeout=30s keepAliveWithoutCalls=YES maxInboundMessageSize=10 databaseId=(default) emulatorHost=127.0.0.1:8500 host=firestore.googleapis.com:443 initialRetryDelay=1s initialRpcTimeout=50s maxAttempts=6 maxRetryDelay=32s maxRpcTimeout=50s retryDelayMultiplier=2 rpcTimeoutMultiplier=1 totalTimeout=50s serviceName=FIRESTOREset cloudconfiguration firestore1 keepAliveTime=2m keepAliveTimeout=1m keepAliveWithoutCalls=NOget cloudconfiguration firestore1 keepAliveTime keepAliveTimeout keepAliveWithoutCallsshow cloudconfiguration firestore1delete cloudconfiguration firestore1export cloudconfiguration ccf.jsonimport cloudconfiguration ccf.jsonfirestoreHandle.collection(String path)<cfscript>
cred = {
projectId : "my-gcp-project",
vendorName: "GCP",
credentialJsonFilePath : "File-path-cred.json"
};
conf = {
serviceName: "firestore"
};
db=getCloudService(cred, conf)
// create the document
docData = ${
name: "Bangalore",
state: "KA",
country: "INDIA"
}
// add document to the collection
res = db.collection("cities_D").runQuery().get();
// get the document
writeOutput(ArrayLen(res.getDocuments()))
</cfscript>FirestoreHandle.collectionGroup(String id)<cfscript>
cred = {
projectId : "my-gcp-project",
vendorName: "GCP",
credentialJsonFilePath : "File-path-cred.json"
};
conf = {
serviceName: "firestore"
};
db=getCloudService(cred, conf)
// Creates and returns a new CollectionGroup that includes all documents in the database that are contained in a collection or subcollection with the given id
reviews=db.collectionGroup("reviews")
query=reviews.whereEqualTo("author","ravi")
results = query.runQuery().get()
writeDump(results)
</cfscript>firestoreHandle.listCollections()<cfscript>
cred = {
projectId : "my-gcp-project",
vendorName: "GCP",
credentialJsonFilePath : "File-path-cred.json"
};
conf = {
serviceName: "firestore"
};
db=getCloudService(cred, conf)
// get list of all collections in a db
collections=db.listCollections()
// get number of collections
writeOutput(collections.size())
</cfscript>firestoreHandle.getAll(Array paths,Array masks)<cfscript>
cred = {
projectId : "my-gcp-project",
vendorName: "GCP",
credentialJsonFilePath : "File-path-cred.json"
};
conf = {
serviceName: "firestore"
};
db=getCloudService(cred, conf)
gettAllData=db.getAll([db.document("Restaurants_D/restaurant1"), db.document("Restaurants_D/restaurant3")], ["LOCATION", "NAME"]).get()
cfloop(array="#gettAllData#", item="itm")
{
cfloop(collection = "#itm.getData()#",item = "key")
{
writeOutput(key);
writeOutput(" ");
writeOutput(itm.getData()[key]);
writeOutput(" ");
}
}
</cfscript>FirestoreHandle.document(String id) <cfscript>
cred = {
projectId : "my-gcp-project",
vendorName: "GCP",
credentialJsonFilePath : "File-path-cred.json"
};
conf = {
serviceName: "firestore"
};
db=getCloudService(cred, conf)
docRef = db.collection("Ecom_D").document("Order2");
docData = ${
OrderID: 1002233,
ItemID: 00001,
Price: 499.00,
Seller: "ABC"
}
docRef.set(docData).get()
writeOutput(docRef.getDocument().get().getID())
//writeOutput(docRef.getDocument().get())
</cfscript>add(struct data)<cfscript>
cred = {
projectId : "my-project-id",
credentialJsonFilePath : "Path-creds-file.json"
};
conf = {
serviceName : "firestore"
};
db=getCloudService(cred,conf)
docData=${
firstName: "Jack",
lastName: "Sparrow",
age2: #Int(22)#,
arrMarks: [89,90,91,92],
percentage: 90.54,
isPass: True,
feeDue: "Null"
}
// add the data
response=db.collection("Student_D").add(docData).get()
writeDump(response)
</cfscript>add(cfobject data)<cfscript>
cred = {
projectId : "my-project-id",
credentialJsonFilePath : "Path-creds-file.json"
};
conf = {
serviceName : "firestore"
};
db=getCloudService(cred,conf)
objPerson = new testFiles._Person("Jack", "Sparrow", 8989898989);
response=db.collection("Users_D").add(objPerson).get()
writeDump(response)
</cfscript>create(Struct data)<cfscript>
cred = {
projectId : "my-project-id",
credentialJsonFilePath : "Path-creds-file.json"
};
conf = {
serviceName : "firestore"
};
db=getCloudService(cred,conf)
docSchool2=${
name:"NYU",
location:"NY",
year:2010
}
try{
createResponse=db.collection("Coll_Doc_2").document("doc_Doc_2").create(docSchool2).get()
writeOutput("Document created successfully")
writeDump(createResponse)
}
catch(any e){
writeDump(e)
}
</cfscript>getAll(Array documentReferences)<cfscript>
cred = {
projectId : "my-project-id",
vendorName: "GCP",
credentialJsonFilePath : "Path-creds-file.json"
};
conf = {
serviceName: "firestore"
};
db=getCloudService(cred, conf)
docRef1 = db.collection("Cities_s").document("SF15");
docRef2 = db.collection("Cities_s").document("SF16");
docData = ${
Country: "USA",
Population: 901
}
docData1 = ${
Country: "USA",
Population: 902
}
docRef1.set(docData).get();
docRef2.set(docData1).get();
returnValue = db.runTransaction(transaction => {
try {
getAllFuture=transaction.getAll([docRef1, docRef2], ["Population"]).get();
cfloop(array="#getAllFuture#", item="itm")
{
cfloop(collection = "#itm.getData()#",item = "key");
{
if(itm.getData()["Population"] > 900)
transaction.update(db.document(itm.getPath()), {"Population" : itm.getData()["Population"]+1});
}
}
return transaction;
}
catch (any e)
{ return e; }
}).get();
</cfscript>create(cfobject data)<cfscript>
cred = {
projectId : "my-project-id",
credentialJsonFilePath : "Path-creds-file.json"
};
conf = {
serviceName : "firestore"
};
db=getCloudService(cred,conf)
db = getCloudService(this.cred, this.conf);
objPerson1 = new testFiles._Person("Jack", "Sparrow", 9090909090);
response=db.collection("Users_D").document().create(objPerson1).get()
writeDump(response)
</cfscript>set(Struct data)<cfscript>
cred = {
projectId : "my-project-id",
credentialJsonFilePath : "Path-creds-file.json"
};
conf = {
serviceName : "firestore"
};
db=getCloudService(cred,conf)
for (i = 1; i <= 5; i++) {
docData = ${
name: "Chicago"&i,
state: "IL"&i,
country: "USA"&i
}
response=db.collection("cities_D").document(i).set(docData); //Updating the document
writeDump(response)
}
</cfscript>set(cfobject data)<cfscript>
cred = {
projectId : "my-project-id",
credentialJsonFilePath : "Path-creds-file.json"
};
conf = {
serviceName : "firestore"
};
db=getCloudService(cred,conf)
objPerson = new testFiles._Person("Joy", "Division", 8989898989);
future = runAsync(x => db.collection("Users_D").document("D1").set(objPerson).get())
writeDump(future)
</cfscript>update(Struct fields)<cfscript>
cred = {
projectId : "my-project-id",
credentialJsonFilePath : "Path-creds-file.json"
};
conf = {
serviceName : "firestore"
};
db=getCloudService(cred,conf)
docRef = db.collection("Cities_D").document("SF12");
docData = ${
Country: "USA",
Population: 860000
}
docData1 = ${
Country: "USA",
Population: 90000
}
docRef.set(docData).get();
createdDate=docRef.getDocument().get().getCreateTime();
response=docRef.update(docData1,createdDate).get()
writeDump(response)
</cfscript>update(Struct fields, dateTime timestamp)<cfscript>
cred = {
projectId : "my-project-id",
credentialJsonFilePath : "Path-creds-file.json"
};
conf = {
serviceName : "firestore"
};
db=getCloudService(cred,conf)
docRef = db.collection("Cities_D").document("SF12");
docData = ${
Country: "USA",
Population: 860000
}
docData1 = ${
Country: "USA",
Population: 90000
}
docRef.set(docData).get();
createdDate=docRef.getDocument().get().getCreateTime();
docRef.update(docData1,createdDate).get(); //Trying to update with the datetime precondition.
writeOutput("Population is updated")
response=db.document("Cities_D/SF12").getDocument().get().getData()["Population"]);
writeDump(response)
</cfscript><cfscript>
aUser = ${
firstName: "Harry",
lastName: "Potter",
age: 14,
address: "Hogwarts"
}
harry = db.document("users/harry");
fileHandle = fileOpen(ExpandPath("./crudDump.txt"), "write");
harry.set(aUser).then(
resultFromFirestore => {
fileappend(fileHandle, resultFromFirestore);
harry.getDocument()
.then(result => {
fileappend(fileHandle, serialize(result.getData(),"json"));
}
).error(ex => {
fileappend(fileHandle, ex.getMessage());
})
}
)
.error(ex => {
fileappend(fileHandle, ex.getMessage());
})
</cfscript>getID()<cfscript>
cred = {
projectId : "my-gcp-project",
vendorName: "GCP",
credentialJsonFilePath : "File-path-cred.json"
};
conf = {
serviceName: "firestore"
};
db=getCloudService(cred, conf)
docRef = db.collection("Ecom_D").document("Order2");
docData = ${
OrderID: 1002233,
ItemID: 00001,
Price: 499.00,
Seller: "ABC"
}
docRef.set(docData).get()
writeOutput(docRef.getDocument().get().getID())
</cfscript>getPath()<cfscript>
cred = {
projectId : "my-gcp-project",
vendorName: "GCP",
credentialJsonFilePath : "File-path-cred.json"
};
conf = {
serviceName: "firestore"
};
db=getCloudService(cred, conf)
docSchool2=${
name:"NYU",
location:"NY",
year:2010
}
try{
getResponse=db.collection("Coll_Doc_7").document("docSchool2").getPath()
}
catch(any e){
writeDump(e)
}
</cfscript>getParent()<cfscript>
cred = {
projectId : "my-gcp-project",
credentialJsonFilePath : "File-path-cred.json"
};
conf = {
serviceName : "firestore"
};
db=getCloudService(cred,conf)
docSchool2=${
name:"NYU",
location:"NY",
year:2010
}
getParentResponse=db.collection("School_Doc").document("school1").getParent().getID();
writeDump(getParentResponse)
</cfscript>collection(String path)<cfscript>
cred = {
projectId : "my-gcp-project",
vendorName: "GCP",
credentialJsonFilePath : "File-path-cred.json"
};
conf = {
serviceName: "firestore"
};
db=getCloudService(cred, conf)
// create the document
docData = ${
name: "Bangalore",
state: "KA",
country: "INDIA"
}
// add document to the collection
res = db.collection("cities_D").runQuery().get();
// get the response
writeDump(res)
// get the document
writeOutput(ArrayLen(res.getDocuments()))
</cfscript>create(Struct docName)<cfscript>
cred = {
projectId : "my-gcp-project",
credentialJsonFilePath : "File-path-cred.json"
};
conf = {
serviceName : "firestore"
};
db=getCloudService(cred,conf)
docSchool2=${
name:"NYU",
location:"NY",
year:2010
}
try{
createResponse=db.collection("Coll_Doc_2").document("doc_Doc_2").create(docSchool2).get()
writeOutput("Collection created successfully")
writeDump(createResponse)
}
catch(any e){
writeDump(e)
}
</cfscript>delete()<cfscript>
cred = {
projectId : "my-gcp-project",
credentialJsonFilePath : "File-path-cred.json"
};
conf = {
serviceName : "firestore"
};
db=getCloudService(cred,conf)
// db.collection("School_Doc").document("school1").delete();
docSchool2=${
name:"NYU",
location:"NY",
year:2010
}
try{
deleteResponse=db.collection("Coll_Doc_5").document("doc_Doc_5").delete()
writeOutput("Document deleted successfully")
writeDump(deleteResponse)
}
catch(any e){
writeDump(e
}
</cfscript>update(structData)<cfscript>
cred = {
projectId : "my-gcp-project",
credentialJsonFilePath : "File-path-cred.json"
};
conf = {
serviceName : "firestore"
};
db=getCloudService(cred,conf)
// db.collection("School_Doc").document("school1").update(docSchool2).get()
docSchool2=${
name:"NYU",
location:"NY",
year:2010
}
try{
updateResponse=db.collection("Coll_Doc_4").document("doc_Doc_3").update(docSchool2)
writeOutput("Document updated successfully")
writeDump(updateResponse)
}
catch(any e){
writeDump(e)
}
</cfscript><cfscript>
cred = {
projectId : "my-gcp-project",
credentialJsonFilePath : "File-path-cred.json"
};
conf = {
serviceName : "firestore"
};
db=getCloudService(cred,conf)
students=db.collection("students_p");
query=students.orderBy("last_name");
results = query.runQuery().get();
</cfscript><cfscript>
cred = {
projectId : "my-gcp-project",
credentialJsonFilePath : "File-path-cred.json"
};
conf = {
serviceName : "firestore"
};
db=getCloudService(cred,conf)
students=db.collection("students_p");
query=students.orderBy("last_name").limit(20);
results = query.runQuery().get();
writeDump(results)
</cfscript><cfscript>
db = getCloudService(Application.cred, Application.conf);
students=db.collection("students_p");
query=students.orderBy("first_name","descending");
results = query.runQuery().get();
writeDump(results)
</cfscript><cfscript>
cred = {
projectId : "my-gcp-project",
credentialJsonFilePath : "File-path-cred.json"
};
conf = {
serviceName : "firestore"
};
db=getCloudService(cred,conf)
students=db.collection("students_p");
query=students.orderBy("first_name").limittolast(3);
results = query.runQuery().get();
writeDump(results)
</cfscript><cfscript>
cred = {
projectId : "my-gcp-project",
credentialJsonFilePath : "File-path-cred.json"
};
conf = {
serviceName : "firestore"
};
db=getCloudService(cred,conf)
students=db.collection("students_p")
query=students.offset(5)
results = query.runQuery().get()
writeDump(results)
</cfscript><cfscript>
cred = {
projectId : "my-gcp-project",
credentialJsonFilePath : "File-path-cred.json"
};
conf = {
serviceName : "firestore"
};
db=getCloudService(cred,conf)
locations=db.collection("locations_p");
query=locations.orderBy("rating").orderBy("name").limit(20)
results=query.startAfter([3.8,"Sarkhej Roza"]).limit(20)
writeDump(results)
</cfscript><cfscript>
cred = {
projectId : "my-gcp-project",
credentialJsonFilePath : "File-path-cred.json"
};
conf = {
serviceName : "firestore"
};
db=getCloudService(cred,conf)
db = getCloudService(Application.cred, Application.conf);
locations=db.collection("locations_p");
query=locations.orderBy("rating").startAt([4.1]);
results=query.runQuery().get()
writeDump(results)
</cfscript><cfscript>
cred = {
projectId : "my-gcp-project",
credentialJsonFilePath : "File-path-cred.json"
};
conf = {
serviceName : "firestore"
};
db=getCloudService(cred,conf)
locations=db.collection("locations_p");
query=locations.orderBy("rating").endAt([4.6]);
results=query.runQuery().get()
writeDump(results)
</cfscript><cfscript>
cred = {
projectId : "my-gcp-project",
credentialJsonFilePath : "File-path-cred.json"
};
conf = {
serviceName : "firestore"
};
locations=db.collection("locations_p");
query=locations.orderBy("rating").endBefore([4.6]);
results=query.runQuery().get()
writeDump(results)
</cfscript><cfscript>
db = getCloudService(Application.cred, Application.conf);
locations=db.collection("locations_p");
myquery=locations.orderBy("rating")
results=myquery.runQuery().get();
count=results.size();
startDocument=results.getDocuments()[10];
myquery=locations.orderBy("rating").startAfter(startDocument)
results=myquery.runQuery().get();
writeDump(results)
</cfscript><cfscript>
db = getCloudService(Application.cred, Application.conf);
count=0;
locations=db.collection("locations_p");
myquery=locations.orderBy("rating")
results=myquery.runQuery().get();
startDocument=results.getDocuments()[7];
myquery=locations.orderBy("rating").startAt(startDocument)
results=myquery.runQuery().get();
writeDump(results)
</cfscript><cfscript>
db = getCloudService(Application.cred, Application.conf);
locations=db.collection("locations_p");
myquery=locations.orderBy("rating")
results=myquery.runQuery().get();
endDocument=results.getDocuments()[results.size()-2];
myquery=locations.orderBy("rating").endAt(endDocument);
results=myquery.runQuery().get();
writeDump(results)
</cfscript><cfscript>
db = getCloudService(Application.cred, Application.conf);
locations=db.collection("locations_p");
myquery=locations.orderBy("rating")
results=myquery.runQuery().get();
endDocument=results.getDocuments()[15];
myquery=locations.orderBy("rating").endBefore(endDocument)
results=myquery.runQuery().get();
writeDump(results)
</cfscript>create(DocumentReference documentReference, Struct data)<cfscript>
cred = {
projectId : "my-project-id",
vendorName: "GCP",
credentialJsonFilePath : "Path-creds-file.json"
};
conf = {
serviceName: "firestore"
};
db=getCloudService(cred, conf)
docData = ${
LOCATION: "5th Avenue",
NAME: "John's",
TYPE: "Thai",
TOTAL: 10
}
db.document("Restaurants_D/Restaurant4").create(docData).get();
returnValue = db.runTransaction(transaction => {
try {
restaurant4=db.document("Restaurants_D/Restaurant4");
number = transaction.getDocument(restaurant4).get().getData()["TOTAL"];
review1 = db.document("Restaurants_D/Restaurant4/Reviews/review1");
transaction.create(review1,{"rating": 5});
transaction.update(restaurant4, {"TOTAL" : number+1})
return transaction
}
catch (any e)
{ return e; }
}).get()
</cfscript>create(DocumentReference documentReference, CFObject data)<cfscript>
cred = {
projectId : "my-project-id",
vendorName: "GCP",
credentialJsonFilePath : "Path-creds-file.json"
};
conf = {
serviceName: "firestore"
};
db=getCloudService(cred, conf)
objPerson = new testFiles._Person("Jack", "Sparrow", 900);
db.document("Users_D/usr1").create(objPerson).get();
db.runTransaction(transaction => {
try {
usr1=db.document("Users_D/usr1");
number = transaction.getDocument(usr1).get().getData()["phonenumber"];
comment1 = db.document("Users_D/usr1/Comment/comment1");
transaction.create(comment1,{"comment1": "Test Comment."});
transaction.update(usr1, {"phonenumber" : number+1})
return transaction
}
catch (any e)
{ return e; }
}).get()
</cfscript>set(DocumentReference documentReference, Struct data)<cfscript>
cred = {
projectId : "my-project-id",
vendorName: "GCP",
credentialJsonFilePath : "Path-creds-file.json"
};
conf = {
serviceName: "firestore"
};
db=getCloudService(cred, conf)
db = getCloudService(this.cred, this.conf);
db.collection("Cities_D").document("SF");
docData = ${
Country: "USA",
Population: 860000
}
docRef.set(docData).get();
returnValue = db.runTransaction(transaction => {
try {
number = transaction.getDocument(docRef).get().getData()["Population"];
transaction.update(docRef, {"Population" : number+1});
return transaction;
}
catch (any e)
{ return e; }
}).get()
</cfscript>set(DocumentReference documentReference, CFObject data)component
{
function deleteDoc(docRef)
{
collections = docRef.listCollections();
for(collection in collections)
deleteCol(collection);
docRef.delete().get();
}
function deleteCol(colRef)
{
documents = colRef.listDocuments();
for(document in documents)
deleteDoc(document);
}
}<cfscript>
cred = {
projectId : "my-project-id",
vendorName: "GCP",
credentialJsonFilePath : "Path-creds-file.json"
};
conf = {
serviceName: "firestore"
};
db=getCloudService(cred, conf)
obj=CreateObject("component","_deleteDoc");
docRef = db.collection("Cities_D").document("SF3");
docData = ${
Country: "USA",
Population: 860000
}
docData1 = ${
Country: "USA",
Population: 900000
}
if(db.document("Cities_D/SF3").getDocument().get().exists())
obj.deleteDoc(docRef);
docRef.create(docData).get();
returnValue = db.runTransaction(transaction => {
try {
Population = transaction.getDocument(docRef).get().getData()["Population"];
transaction.set(docRef,docData1);
newPopulation= Population+1;
return newPopulation;
}
catch (any e)
{ return e; }
}).get()
</cfscript>update(DocumentReference documentReference, Struct fields)docRef = db.collection("Cities_D").document("SF10");
docData = ${
Country: "USA",
Population: 860000
}
docData1 = ${
Country: "USA",
Population: 900000
}
docRef.create(docData).get();
db.runTransaction(trans => {
try {
Population = trans.getDocument(docRef).get().getData()["Population"];
trans.update(docRef,docData1);
return trans;
}
catch (any e)
{ return e; }
}).get()delete(DocumentReference documentReference)<cfscript>
cred = {
projectId : "my-project-id",
vendorName: "GCP",
credentialJsonFilePath : "Path-creds-file.json"
};
conf = {
serviceName: "firestore"
};
db=getCloudService(cred, conf)
docData = ${
Country: "USA",
Population: 860000
}
docRef.set(docData).get();
db.runTransaction(transaction => {
try {
Population = transaction.getDocument(docRef).get().getData()["Population"];
newPopulation= Population+1;
if(Population <= 860000)
{
transaction.update(docRef, {"Population" : newPopulation});
transaction.delete(docRef);
return "Document deleted successfully inside Transaction !!";
}
else
return "Sorry! Population is too big.";
}
catch (any e)
{ return e; }
}).get()
</cfscript>runQuery(Query query)<cfscript>
cred = {
projectId : "my-project-id",
vendorName: "GCP",
credentialJsonFilePath : "Path-creds-file.json"
};
conf = {
serviceName: "firestore"
};
db=getCloudService(cred, conf)
docRef = db.collection("Cities_D").document("SF8");
docData = ${
Country: "USA",
Population: 860000,
count: 8
}
docRef.set(docData).get();
cities=db.collection("Cities_D");
query=cities.whereEqualTo("count",8);
db.runTransaction(transaction => {
try {
number = transaction.runQuery(query).get().getDocuments()[1].getData()["Population"];
transaction.update(docRef, {"Population" : number+1});
return transaction;
}
catch (any e)
{ return e; }
}).get()
</cfscript>hasTransactionId()<cfscript>
cred = {
projectId : "my-project-id",
vendorName: "GCP",
credentialJsonFilePath : "Path-creds-file.json"
};
conf = {
serviceName: "firestore"
};
db=getCloudService(cred, conf)
docRef = db.collection("Cities_D").document("SF");
docData = ${
Country: "USA",
Population: 860000
}
docData1 = ${
Country: "USA",
Population: 900000,
count: 1
}
docRef.set(docData).get();
returnValue = db.runTransaction(transaction => {
try {
Population = transaction.getDocument(docRef).get().getData()["Population"];
transaction.set(docRef,docData1);
newPopulation= Population+1;
transaction.update(docRef, {"Population" : newPopulation});
return transaction;
}
catch (any e)
{ return e; }
}).get();
writeOutput("HasTransactionID " & returnValue.hasTransactionId())
</cfscript>getMutationSize()<cfscript>
cred = {
projectId : "my-project-id",
vendorName: "GCP",
credentialJsonFilePath : "Path-creds-file.json"
};
conf = {
serviceName: "firestore"
};
db=getCloudService(cred, conf)
docRef = db.collection("Cities_D").document("SF");
docData = ${
Country: "USA",
Population: 860000
}
docData1 = ${
Country: "USA",
Population: 900000,
count: 1
}
docRef.set(docData).get();
returnValue = db.runTransaction(transaction => {
try {
Population = transaction.getDocument(docRef).get().getData()["Population"];
transaction.set(docRef,docData1);
newPopulation= Population+1;
transaction.update(docRef, {"Population" : newPopulation});
return transaction;
}
catch (any e)
{ return e; }
}).get();
writeOutput("MutationSize is " & returnValue.getMutationSize())
</cfscript><cfscript>
aUser = ${
firstName: "Harry",
lastName: "Potter",
age: 14,
address: "Hogwarts"
}
harry = db.document("users/harry");
fileHandle = fileOpen(ExpandPath("./crudDump.txt"), "write");
harry.set(aUser).then(
resultFromFirestore => {
fileappend(fileHandle, resultFromFirestore);
harry.getDocument()
.then(result => {
fileappend(fileHandle, serialize(result.getData(),"json"));
}
).error(ex => {
fileappend(fileHandle, ex.getMessage());
})
}
)
.error(ex => {
fileappend(fileHandle, ex.getMessage());
})
</cfscript>addSnapshotListener(UDFMethod onSuccess, UDFMethod onFailure)<cfscript>
cred = {
projectId : "my-project-id",
credentialJsonFilePath : "Path-creds-file.json"
};
conf = {
serviceName : "firestore"
};
pubSubClient=getCloudService(cred,conf)
docFuture = db.collection("stock_p").document("doc");
path=ExpandPath("./documentSnapshot.txt")
onSuccess = results => {
fileAppend(path, serialize(results,"json"));
}
onFailure = exception => {
fileAppend(path, exception.getMessage());
}
docFuture.addSnapshotListener(onSuccess, onFailure)
</cfscript>addSnapshotListener(UDFMethod onSuccess, UDFMethod onFailure)<cfscript>
cred = {
projectId : "my-project-id",
credentialJsonFilePath : "Path-creds-file.json"
};
conf = {
serviceName : "firestore"
};
pubSubClient=getCloudService(cred,conf)
stocks = db.collection("stock_p")
path=ExpandPath("./documentSnapshot.txt")
onSuccess = result => {
fileAppend(path, serialize(result.documentChanges,"json"));
}
onFailure = exception => {
fileAppend(path, exception.getMessage());
}
stocks.addSnapshotListener(onSuccess, onFailure)
</cfscript>create(DocumentReference documentReference, Struct data)<cfscript>
cred = {
projectId : "my-project-id",
vendorName: "GCP",
credentialJsonFilePath : "Path-creds-file.json"
};
conf = {
serviceName: "firestore"
};
db=getCloudService(cred, conf)
docData = ${
LOCATION: "5th Avenue",
NAME: "John's",
TYPE: "Thai",
TOTAL: 10
}
db.document("Restaurants_D/Restaurant4").create(docData).get();
returnValue = db.runTransaction(transaction => {
try {
restaurant4=db.document("Restaurants_D/Restaurant4");
number = transaction.getDocument(restaurant4).get().getData()["TOTAL"];
review1 = db.document("Restaurants_D/Restaurant4/Reviews/review1");
transaction.create(review1,{"rating": 5});
transaction.update(restaurant4, {"TOTAL" : number+1})
return transaction
}
catch (any e)
{ return e; }
}).get()
</cfscript>create(DocumentReference documentReference, CFObject data)<cfscript>
cred = {
projectId : "my-project-id",
vendorName: "GCP",
credentialJsonFilePath : "Path-creds-file.json"
};
conf = {
serviceName: "firestore"
};
db=getCloudService(cred, conf)
objPerson = new testFiles._Person("Jack", "Sparrow", 900);
db.document("Users_D/usr1").create(objPerson).get();
db.runTransaction(transaction => {
try {
usr1=db.document("Users_D/usr1");
number = transaction.getDocument(usr1).get().getData()["phonenumber"];
comment1 = db.document("Users_D/usr1/Comment/comment1");
transaction.create(comment1,{"comment1": "Test Comment."});
transaction.update(usr1, {"phonenumber" : number+1})
return transaction
}
catch (any e)
{ return e; }
}).get()
</cfscript>set(DocumentReference documentReference, Struct data)<cfscript>
cred = {
projectId : "my-project-id",
vendorName: "GCP",
credentialJsonFilePath : "Path-creds-file.json"
};
conf = {
serviceName: "firestore"
};
db=getCloudService(cred, conf)
db = getCloudService(this.cred, this.conf);
db.collection("Cities_D").document("SF");
docData = ${
Country: "USA",
Population: 860000
}
docRef.set(docData).get();
returnValue = db.runTransaction(transaction => {
try {
number = transaction.getDocument(docRef).get().getData()["Population"];
transaction.update(docRef, {"Population" : number+1});
return transaction;
}
catch (any e)
{ return e; }
}).get()
</cfscript>set(DocumentReference documentReference, CFObject data)component
{
function deleteDoc(docRef)
{
collections = docRef.listCollections();
for(collection in collections)
deleteCol(collection);
docRef.delete().get();
}
function deleteCol(colRef)
{
documents = colRef.listDocuments();
for(document in documents)
deleteDoc(document);
}
}<cfscript>
cred = {
projectId : "my-project-id",
vendorName: "GCP",
credentialJsonFilePath : "Path-creds-file.json"
};
conf = {
serviceName: "firestore"
};
db=getCloudService(cred, conf)
obj=CreateObject("component","_deleteDoc");
docRef = db.collection("Cities_D").document("SF3");
docData = ${
Country: "USA",
Population: 860000
}
docData1 = ${
Country: "USA",
Population: 900000
}
if(db.document("Cities_D/SF3").getDocument().get().exists())
obj.deleteDoc(docRef);
docRef.create(docData).get();
returnValue = db.runTransaction(transaction => {
try {
Population = transaction.getDocument(docRef).get().getData()["Population"];
transaction.set(docRef,docData1);
newPopulation= Population+1;
return newPopulation;
}
catch (any e)
{ return e; }
}).get()
</cfscript>update(DocumentReference documentReference, Struct fields)docRef = db.collection("Cities_D").document("SF10");
docData = ${
Country: "USA",
Population: 860000
}
docData1 = ${
Country: "USA",
Population: 900000
}
docRef.create(docData).get();
db.runTransaction(trans => {
try {
Population = trans.getDocument(docRef).get().getData()["Population"];
trans.update(docRef,docData1);
return trans;
}
catch (any e)
{ return e; }
}).get()delete(DocumentReference documentReference)<cfscript>
cred = {
projectId : "my-project-id",
vendorName: "GCP",
credentialJsonFilePath : "Path-creds-file.json"
};
conf = {
serviceName: "firestore"
};
db=getCloudService(cred, conf)
docData = ${
Country: "USA",
Population: 860000
}
docRef.set(docData).get();
db.runTransaction(transaction => {
try {
Population = transaction.getDocument(docRef).get().getData()["Population"];
newPopulation= Population+1;
if(Population <= 860000)
{
transaction.update(docRef, {"Population" : newPopulation});
transaction.delete(docRef);
return "Document deleted successfully inside Transaction !!";
}
else
return "Sorry! Population is too big.";
}
catch (any e)
{ return e; }
}).get()
</cfscript>runQuery(Query query)<cfscript>
cred = {
projectId : "my-project-id",
vendorName: "GCP",
credentialJsonFilePath : "Path-creds-file.json"
};
conf = {
serviceName: "firestore"
};
db=getCloudService(cred, conf)
docRef = db.collection("Cities_D").document("SF8");
docData = ${
Country: "USA",
Population: 860000,
count: 8
}
docRef.set(docData).get();
cities=db.collection("Cities_D");
query=cities.whereEqualTo("count",8);
db.runTransaction(transaction => {
try {
number = transaction.runQuery(query).get().getDocuments()[1].getData()["Population"];
transaction.update(docRef, {"Population" : number+1});
return transaction;
}
catch (any e)
{ return e; }
}).get()
</cfscript>hasTransactionId()<cfscript>
cred = {
projectId : "my-project-id",
vendorName: "GCP",
credentialJsonFilePath : "Path-creds-file.json"
};
conf = {
serviceName: "firestore"
};
db=getCloudService(cred, conf)
docRef = db.collection("Cities_D").document("SF");
docData = ${
Country: "USA",
Population: 860000
}
docData1 = ${
Country: "USA",
Population: 900000,
count: 1
}
docRef.set(docData).get();
returnValue = db.runTransaction(transaction => {
try {
Population = transaction.getDocument(docRef).get().getData()["Population"];
transaction.set(docRef,docData1);
newPopulation= Population+1;
transaction.update(docRef, {"Population" : newPopulation});
return transaction;
}
catch (any e)
{ return e; }
}).get();
writeOutput("HasTransactionID " & returnValue.hasTransactionId())
</cfscript>getMutationSize()<cfscript>
cred = {
projectId : "my-project-id",
vendorName: "GCP",
credentialJsonFilePath : "Path-creds-file.json"
};
conf = {
serviceName: "firestore"
};
db=getCloudService(cred, conf)
docRef = db.collection("Cities_D").document("SF");
docData = ${
Country: "USA",
Population: 860000
}
docData1 = ${
Country: "USA",
Population: 900000,
count: 1
}
docRef.set(docData).get();
returnValue = db.runTransaction(transaction => {
try {
Population = transaction.getDocument(docRef).get().getData()["Population"];
transaction.set(docRef,docData1);
newPopulation= Population+1;
transaction.update(docRef, {"Population" : newPopulation});
return transaction;
}
catch (any e)
{ return e; }
}).get();
writeOutput("MutationSize is " & returnValue.getMutationSize())
</cfscript><cfscript>
aUser = ${
firstName: "Harry",
lastName: "Potter",
age: 14,
address: "Hogwarts"
}
harry = db.document("users/harry");
fileHandle = fileOpen(ExpandPath("./crudDump.txt"), "write");
harry.set(aUser).then(
resultFromFirestore => {
fileappend(fileHandle, resultFromFirestore);
harry.getDocument()
.then(result => {
fileappend(fileHandle, serialize(result.getData(),"json"));
}
).error(ex => {
fileappend(fileHandle, ex.getMessage());
})
}
)
.error(ex => {
fileappend(fileHandle, ex.getMessage());
})
</cfscript>batch()<cfscript>
cred = {
projectId : "my-gcp-project",
credentialJsonFilePath : "File-path-cred.json"
};
conf = {
serviceName : "firestore"
};
db=getCloudService(cred,conf)
batch = db.batch();
docData1 = ${
Country: "USA",
Population: 10
}
docData2 = ${
Country: "India",
Population: 200
}
docData3 = ${
Country: "India",
Population: 400
}
docRef1 = db.collection("BW_S").document("BW1");
docRef2 = db.collection("BW_S").document("BW2");
batch.set(docRef1, docData1);
batch.set(docRef2, docData2);
batch.update(docRef2, docData3);
batch.commit().get();
</cfscript><cfscript>
cred = {
projectId : "my-gcp-project",
credentialJsonFilePath : "File-path-cred.json"
};
conf = {
serviceName : "firestore"
};
db=getCloudService(cred,conf)
students=db.collection("students_p");
query=students.whereEqualTo("age",16);
results = query.runQuery().get();
documents=results.getdocuments()
for(i=1;i<=results.size();i++){
writeDump(documents[i].getdata())
}
</cfscript><cfscript>
cred = {
projectId : "my-gcp-project",
credentialJsonFilePath : "File-path-cred.json"
};
conf = {
serviceName : "firestore"
};
db=getCloudService(cred,conf)
reviews=db.collectionGroup("reviews");
query=reviews.whereNotEqualTo("author","ravi");
results = query.runQuery().get()
documents=results.getdocuments()
for(i=1;i<=results.size();i++){
writeDump(documents[i].getdata())
}
</cfscript><cfscript>
cred = {
projectId : "my-gcp-project",
credentialJsonFilePath : "File-path-cred.json"
};
conf = {
serviceName : "firestore"
};
db=getCloudService(cred,conf)
reviews=db.collection("restaurants_p/6gaKC7syRE1qUGOD0cZZ/reviews");
query=reviews.whereGreaterThanOrEqualTo("rating",4).select(["author"]);
results = query.runQuery().get()
writeDump(results)
</cfscript><cfscript>
cred = {
projectId : "my-gcp-project",
credentialJsonFilePath : "File-path-cred.json"
};
conf = {
serviceName : "firestore"
};
db=getCloudService(cred,conf)
students=db.collection("students_p");
query=students.whereLessThanOrEqualTo("age",15);
results = query.runQuery().get()
writeDump(results)
</cfscript><cfscript>
cred = {
projectId : "my-gcp-project",
credentialJsonFilePath : "File-path-cred.json"
};
conf = {
serviceName : "firestore"
};
db=getCloudService(cred,conf)
students=db.collection("students_p");
query=students.whereGreaterThan("age",16).orderBy("age");
results = query.runQuery().get();
writeDump(results)
</cfscript><cfscript>
cred = {
projectId : "my-gcp-project",
credentialJsonFilePath : "File-path-cred.json"
};
conf = {
serviceName : "firestore"
};
db=getCloudService(cred,conf)
students=db.collection("students_p");
query=students.whereLessThanOrEqualTo("age",15);
results = query.runQuery().get()
writeDump(results)
</cfscript><cfscript>
cred = {
projectId : "my-gcp-project",
credentialJsonFilePath : "File-path-cred.json"
};
conf = {
serviceName : "firestore"
};
db=getCloudService(cred,conf)
students=db.collection("students_p");
query=students.whereArrayContains("marks",70);
results = query.runQuery().get();
writeDump(results)
</cfscript><cfscript>
cred = {
projectId : "my-gcp-project",
credentialJsonFilePath : "File-path-cred.json"
};
conf = {
serviceName : "firestore"
};
db=getCloudService(cred,conf)
students=db.collection("students_p");
query=students.whereIn("age",[16,17,25,7]);
results = query.runQuery().get();
writeDump(results)
</cfscript><cfscript>
cred = {
projectId : "my-gcp-project",
credentialJsonFilePath : "File-path-cred.json"
};
conf = {
serviceName : "firestore"
};
db=getCloudService(cred,conf)
students=db.collection("students_p");
query=students.whereNotIn("age",[16,17,25,7]);
results = query.runQuery().get()
writeDump(results)
</cfscript><cfscript>
cred = {
projectId : "my-gcp-project",
credentialJsonFilePath : "File-path-cred.json"
};
conf = {
serviceName : "firestore"
};
db=getCloudService(cred,conf)
students=db.collection("students_p");
query=students.whereArrayContainsAny("marks",[71.0,15,0,65.5]);
results = query.runQuery().get()
writeDump(results)
</cfscript><cfscript>
cred = {
projectId : "my-gcp-project",
credentialJsonFilePath : "File-path-cred.json"
};
conf = {
serviceName : "firestore"
};
db=getCloudService(cred,conf)
students=db.collection("students_p");
query=students.whereEqualTo("age",16).select(["first_name","age"]);
results = query.runQuery().get()
writeDump(results)
</cfscript>