Content-Lengthはボディの大きさです。
例えば、
ボディが、以下の場合
q=test&submitSearch=%E6%A4%9C%E7%B4%A2
Content-Lengthは以下です。
38
kinkun's blog
Content-Lengthはボディの大きさです。
例えば、
ボディが、以下の場合
q=test&submitSearch=%E6%A4%9C%E7%B4%A2
Content-Lengthは以下です。
38
Content-Length
ドキュメント作成
//コピー元ドキュメント取得
cont searchDoc;
await firebase.firestore()
.collection('testcolloya')
.doc('testdocoya')
.collection("testcoll")
.where('testfield', '==', 'xxxxxxxxxxxxxxxxxxxx')
.get()
.then(snapshot => {
snapshot.docs.forEach(doc => {
searchDoc = doc.data();
});
});
//取得したドキュメントをコピーしてドキュメント作成
let insertDoc = Object.assign({}, searchDoc);
//ドキュメントのfield変更
insertDoc.testfield = 'testfield';
insertDoc.testfield2 = 'testfield2';
//ドキュメント作成
await firebase.firestore()
.collection('testcolloya')
.doc('testdocoya')
.collection("testcoll")
.add(insertDoc);
コレクションのドキュメント全件取得
//コレクションのドキュメント全件取得
var docData = [];
await firebase.firestore()
.collection('testcolloya')
.doc('testdocoya')
.collection("testcoll")
.get()
.then((doc) => {
if (doc.docs) {
doc.docs.map((d) => {
let data = d.data();
docData.push(data);
});
}
else{
console.log('none');
}
});
ドキュメントId取得
//testfieldが該当の値のtestcollのドキュメントID取得
const documentId;
await firebase.firestore()
.collection('testcolloya')
.doc('testdocoya')
.collection("testcoll")
.where('testfield', '==', '1234xxxxxxxxxxxxx5678')
.get()
.then(snapshot => {
snapshot.docs.forEach(doc => {
documentId = doc.id;
});
});
ドキュメント更新
//testfieldの値の更新
await firebase.firestore()
.collection('testcolloya')
.doc('testdocoya')
.collection("testcoll")
.doc("xxxxxxxxxxxxxxxxxxxx")
.update({
testfield: "testName"
});
ドキュメント削除
//testfieldが該当の値のtestcollのドキュメントID取得
const documentId;
await firebase.firestore()
.collection('testcolloya')
.doc('testdocoya')
.collection("testcoll")
.where('testfield', '==', '1234xxxxxxxxxxxxx5678')
.get()
.then(snapshot => {
snapshot.docs.forEach(doc => {
documentId = doc.id;
});
});
//testcollのドキュメントIDのドキュメント削除
try{
await firebase.firestore()
.collection('testcolloya')
.doc('testdocoya')
.collection("testcoll")
.doc(documentId)
.delete();
}catch(e){
console.log(e);
}
Firestoreでidのわからないdocumentを取得したいときはどうすればいいのか
Getting all documents from one collection in Firestore
const events = await firebase.firestore().collection('users')
events.get().then((querySnapshot) => {
const tempDoc = []
querySnapshot.forEach((doc) => {
var data = doc.data();
console.log(data);
tempDoc.push(data);
})
console.log(tempDoc);
})
匿名認証サンプルコード
const firebaseConfig = {
apiKey: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
authDomain: "sample.firebaseapp.com",
databaseURL: "https://sample.firebaseio.com",
projectId: "sample",
storageBucket: "sample.appspot.com",
messagingSenderId: "XXXXXXXXX",
appId: "1:XXXXXXX:web:XXXXX"
};
const app = firebase.initializeApp(firebaseConfig);
await firebase.auth().signInAnonymously().catch(e => {
console.log(e)
})