[Firebase]クエリでstartAt使用例

クエリでstartAt使用例

            const today = new Date();
            const yyyy = today.getFullYear();
            let mm = today.getMonth() + 1;
            let dd = today.getDate();
            const yyyymmdd = yyyy + "," + mm + "," + dd;
            var startDate = new Date(yyyymmdd);
            
            firebase.firestore()
            .collectionGroup("samplecollection") 
            .orderBy("createdAt", "asc").startAt(startDate)
            .limit(10)
            .get()
            .then(querySnapshot => {
                querySnapshot.forEach(doc => {
                    console.log('success');
                }, (error) => {
                    console.log('error');
                });
            })

[Firebase]コレクションまたはサブコレクションが存在するかどうかを確認

コレクションまたはサブコレクションが存在するかどうかを確認

subCollection2存在確認

const db = firebase.firestore();
const collection1 = db.collection('collection1');

var doc = collection1
.doc("docId1")
.collection('subCollection1')
.doc("subDocId1")
.collection('subCollection2')
.get()
.then(snapshot => {
    console.log(snapshot.docs.length);
    if(snapshot.docs.length > 0){
        console.log(snapshot.docs.length);
    }
    else{
        console.log(snapshot.docs.length);
    }


});