Firestore query by date range

前端 未结 9 907
悲&欢浪女
悲&欢浪女 2020-12-02 12:11

I need the help to query long collection with date range. See the below example document. I wanna query startTime field using date range.

9条回答
  •  失恋的感觉
    2020-12-02 12:42

    For everyone recently using firbase firestore. There's a differency depending on your settings of your firebase implentation (depending on the firebase version).

    Before, firestore was saving Timestamp as a Date, however as described here in the docs the will be replaced soon by a Timestamp object. See the Timestamp docs here.

    You can force your implementation already by adding a setting in your code to force firebase to use Timestamp objects instead of Date like this example:

    var firebaseApp = firebase.initializeApp({
        apiKey: [APIKEY],
        authDomain: [FIREBASEAPPDOMAIN],
        projectId: [PROJECTID]
    });
    
    var firestore = firebase.firestore();
    var settings = { timestampsInSnapshots: true }; // force Timestamp instead of Date
    firestore.settings(settings);
    

提交回复
热议问题