북한은 없다
 {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
FirebaseApp.initializeApp(this)
val db = Firebase.firestore
binding.button2.setOnClickListener {
val eamil = binding.email.text.toString()
val nickName = binding.nickName.text.toString()
val user = hashMapOf(
"email" to eamil,
"nickName" to nickName
)
Toast.makeText(this, "send text", Toast.LENGTH_SHORT).show()
db.collection("hello")
.add(user)
.addOnSuccessListener { documentReference ->
Log.d(TAG, "DocumentSnapshot added with ID: ${documentReference.id}")
}
.addOnFailureListener { e ->
Log.w(TAG, "Error adding document", e)
}
}
}
}
val city = hashMapOf(
"name" to "Los Angeles",
"state" to "CA",
"country" to "USA",
)
db.collection("cities").document("LA")
.set(city)
.addOnSuccessListener { Log.d(TAG, "DocumentSnapshot successfully written!") }
.addOnFailureListener { e -> Log.w(TAG, "Error writing document", e) }
val data = hashMapOf("capital" to true)
db.collection("cities").document("BJ")
.set(data, SetOptions.merge())
val docData = hashMapOf(
"stringExample" to "Hello world!",
"booleanExample" to true,
"numberExample" to 3.14159265,
"dateExample" to Timestamp(Date()),
"listExample" to arrayListOf(1, 2, 3),
"nullExample" to null,
)
val nestedData = hashMapOf(
"a" to 5,
"b" to true,
)
docData["objectExample"] = nestedData
db.collection("data").document("one")
.set(docData)
.addOnSuccessListener { Log.d(TAG, "DocumentSnapshot successfully written!") }
.addOnFailureListener { e -> Log.w(TAG, "Error writing document", e) }
data class City(
val name: String? = null,
val state: String? = null,
val country: String? = null,
@field:JvmField // use this annotation if your Boolean field is prefixed with 'is'
val isCapital: Boolean? = null,
val population: Long? = null,
val regions: List<String>? = null,
)
val city = City(
"Los Angeles",
"CA",
"USA",
false,
5000000L,
listOf("west_coast", "socal"),
)
db.collection("cities").document("LA").set(city)
db.collection("cities").document("new-city-id").set(data)
// Add a new document with a generated id.
val data = hashMapOf(
"name" to "Tokyo",
"country" to "Japan",
)
db.collection("cities")
.add(data)
.addOnSuccessListener { documentReference ->
Log.d(TAG, "DocumentSnapshot written with ID: ${documentReference.id}")
}
.addOnFailureListener { e ->
Log.w(TAG, "Error adding document", e)
}
val washingtonRef = db.collection("cities").document("DC")
// Set the "isCapital" field of the city 'DC'
washingtonRef
.update("capital", true)
.addOnSuccessListener { Log.d(TAG, "DocumentSnapshot successfully updated!") }
.addOnFailureListener { e -> Log.w(TAG, "Error updating document", e) }
val docRef = db.collection("objects").document("some-id")
val updates = hashMapOf<String, Any>(
"timestamp" to FieldValue.serverTimestamp(),
)
docRef.update(updates).addOnCompleteListener { }
// Assume the document contains:
// {
// name: "Frank",
// favorites: { food: "Pizza", color: "Blue", subject: "recess" }
// age: 12
// }
//
// To update age and favorite color:
db.collection("users").document("frank")
.update(
mapOf(
"age" to 13,
"favorites.color" to "Red",
),
)
// Create our initial doc
db.collection("users").doc("frank").set({
name: "Frank",
favorites: {
food: "Pizza",
color: "Blue",
subject: "Recess"
},
age: 12
}).then(function() {
console.log("Frank created");
});
// Update the doc without using dot notation.
// Notice the map value for favorites.
db.collection("users").doc("frank").update({
favorites: {
food: "Ice Cream"
}
}).then(function() {
console.log("Frank food updated");
});
/*
Ending State, favorite.color and favorite.subject are no longer present:
/users
/frank
{
name: "Frank",
favorites: {
food: "Ice Cream",
},
age: 12
}
*/
val washingtonRef = db.collection("cities").document("DC")
// Atomically add a new region to the "regions" array field.
washingtonRef.update("regions", FieldValue.arrayUnion("greater_virginia"))
// Atomically remove a region from the "regions" array field.
washingtonRef.update("regions", FieldValue.arrayRemove("east_coast"))
val washingtonRef = db.collection("cities").document("DC")
// Atomically increment the population of the city by 50.
washingtonRef.update("population", FieldValue.increment(50))