Syed Khizer
Syed Khizer

Reputation: 1

The behavior for Date objects stored in Firestore is going to change and your app may break

I am stuck at this point while working on VueJs as i want to log the data from firebase . I changed the code according to the suggestions on the console but nothing is working . I am using Vue Cli 3 and firebase 5.5.9 .

<script>
import db from './firebaseInit'
export default {
name: 'dashboard',
    data(){
        return{
            employees: []
        }
    },
    created(){
        db.collection('employees').get().then
        (querySnapshot => {
            querySnapshot.forEach(doc => {
                console.log(doc.data())
                const data = {

                }
            })
        })
    }
}
</script>

This is my firebaseInit.js

import firebase from 'firebase'

import 'firebase/firestore'
import firebaseConfig from './firebaseConfig'
const firebaseApp = firebase.initializeApp(firebaseConfig)

// const firestore = firebase.firestore();
// const settings = {timestampsInSnapshots: true};
// firestore.settings(settings);
export default firebaseApp.firestore()

Upvotes: 0

Views: 297

Answers (2)

Touha
Touha

Reputation: 617

import firebase from "firebase";
import "firebase/firestore";
import firebaseConfig from "./firabaseConfig.js";

const firebaseApp = firebase.initializeApp(firebaseConfig);    
firebaseApp.firestore().settings({ timestampsInSnapshots: true });

export default firebaseApp.firestore();

it works for me. you can give it a try. :)

Upvotes: 0

Frank van Puffelen
Frank van Puffelen

Reputation: 598765

As shown in both the error message and this github issue, you need to initialize the firestore object with an instruction on how to store date/timestamp fields.

So:

import firebase from 'firebase'

import 'firebase/firestore'
import firebaseConfig from './firebaseConfig'
const firebaseApp = firebase.initializeApp(firebaseConfig)

const firestore = firebase.firestore();
const settings = {timestampsInSnapshots: true};
const api = firestore.settings(settings);
export default api;

Upvotes: 1

Related Questions