How to use the firebase.firestore function in firebase

To help you get started, we’ve selected a few firebase examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github flow-typed / flow-typed / definitions / npm / firebase_v5.x.x / flow_v0.104.x- / test_firebase.js View on Github external
// #31
firebase
  .firestore()
  .collection('/foo')
  .where('id', '==', '5')
  .get({ source: 'cache' });

// #32
firebase
 .firestore()
 .collection('/foo')
 .where('id', 'array-contains', '5')
 .get({ source: 'cache' });

// #33
firebase
 .firestore()
 .collection('/foo')
 // $ExpectError
 .where('id', 'lte', '5')
 .get({ source: 'cache' });

// #34
firebase
  .firestore()
  .collection('/foo')
  .add({foo: 'bar'})
  .then(document => {
    const id = document.id
  })

// #35
github IjzerenHein / firestorter / examples / importCSV / index.js View on Github external
company: row[0].trim(),
			origin: row[1].trim(),
			reviewDate: new Date(Number(row[3]), 1, 1, 0, 0, 0, 0),
			cocaoPercent: Number(row[4].substring(0, row[4].length - 1)) / 100,
			companyLocation: row[5].trim(),
			rating: Number(row[6]),
			beanType: row[7].trim(),
			broadBeanOrigin: row[8].trim(),
			location: new firebase.firestore.GeoPoint(latitude, longitude),
			geohash: encodeGeohash({
				latitude,
				longitude
			})
		};
		// console.info('Adding ' + i + ' of ' + count + ': ' + row);
		const ref = firebase.firestore().doc('chocolateBars/' + id);
		writeBatch.set(ref, json);
	}
	await writeBatch.commit();
	console.timeEnd('import');
}
github VirgilSecurity / demo-firebase-js / src / models / UserModel.ts View on Github external
{
        headers: new Headers({
            'Content-Type': 'application/json',
                Authorization: `Bearer ${authToken}`,
        })
    },
    );
    if (!response.ok) {
        throw `Error code: ${response.status} \nMessage: ${response.statusText}`;
    }
    return response.json().then(data => data.token);
};


class UserApi {
    collectionRef = firebase.firestore().collection(FirebaseCollections.Users);
    eThree: Promise;

    constructor(public state: AppStore) {
        // here we will keep link to promise with initialized e3kit library
        this.eThree = new Promise((resolve, reject) => {
            firebase.auth().onAuthStateChanged(async user => {
                if (user) {
                    const getToken = () => user.getIdToken().then(fetchToken);
                    // callback onAuthStateChanged can be called with second user, so we make new
                    // reference to e3kit
                    this.eThree = EThree.initialize(getToken);
                    this.eThree.then(resolve).catch(reject);
                    const eThree = await this.eThree;
                    // if user has private key locally, then he didn't logout
                    if (await eThree.hasLocalPrivateKey()) this.openChatWindow(user.email!, eThree)
                } else {
github react-native-seoul / TalkTalk / src / components / shared / ProfileModal.tsx View on Github external
if (snapshots.numChildren() === 0) {
        const newPostKey = firebase.database().ref(`users/${userData.uid}`).child('friends').push().key;

        const updates = {};
        updates['/users/' + userData.uid + '/friends/' + newPostKey] = {
          id: this.state.user.id,
        };
        firebase.database().ref().update(updates);
        this.setState({ isFriendAdded: true });
        return;
      }
      this.setState({ isFriendAlreadyAdded: true });
    });

    // firestore
    const friendCol = firebase.firestore().collection('users').doc(`${userData.uid}`).collection('friends');
    friendCol
    .where('id', '==', this.state.user.id)
    .get().then((snapshots) => {
      if (snapshots.size === 0) {
        friendCol.add({
          id: this.state.user.id,
        });
        this.setState({ isFriendAdded: true });
        return;
      }
      this.setState({ isFriendAlreadyAdded: true });
    });
  }
github firebase / firebase-js-sdk / examples / testing / write.js View on Github external
* Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

const firebase = require('firebase');
const _ = require('firebase/firestore');
firebase.firestore.setLogLevel('debug');

var app = firebase.initializeApp({
  projectId: 'test'
});

var db = firebase.firestore();
db.settings({
  host: 'localhost:8080',
  ssl: false
});

var docRef = db.collection('users').doc('alovelace');

var setAda = docRef.set({
  first: 'Ada',
  last: 'Lovelace',
  born: 1815
});

var aTuringRef = db.collection('users').doc('aturing');

var setAlan = aTuringRef.set({
github react-native-seoul / TalkTalk / src / components / screen / Friend.tsx View on Github external
snapshots.docChanges().forEach((change) => {
          let user = change.doc.data();
          console.log('user', user);
          user.friendId = change.doc.id;
          firebase.firestore().collection('users').doc(user.id).onSnapshot((friendSnap) => {
            if (change.type === 'added') {
              user = { ...user, ...friendSnap.data() };
              friends.push(user);
              if (snapshots.size === friends.length) {
                this.setState({ friends });
                return;
              }
            }

            if (change.type === 'removed') {
              const index = this.state.friends.findIndex((el) => {
                return el.friendId === user.friendId;
              });
              console.log(index);
              this.setState({
                friends: update(
github allenday / nanostream-dataflow / NanostreamDataflowMain / webapp / src / main / app-vue-js / src / views / Vis.vue View on Github external
firebaseInit: function () {
                if (!firebase.apps.length) {
                    console.log('Connect to DB with config:', this.config)
                    firebase.initializeApp(this.config);
                }

                const db = firebase.firestore();
                db.settings({
                    timestampsInSnapshots: true
                });
                console.log('== db init finished ==')
                return db;
            },
github Rajan / lesspod / client / vue / src / store / actions / firebase.js View on Github external
fetchPosts: () => {
    let db = firebase.firestore()
    const settings = {
      timestampsInSnapshots: true
    }
    db.settings(settings)
    return db
      .collection('posts')
      .get()
      .then(function (querySnapshot) {
        let posts1 = []
        querySnapshot.forEach(function (doc) {
          posts1.push(doc.data())
        })
        for (var i in posts1) {
          if (posts1[i].pageURL && posts1[i].pageURL.length !== 0) {
            posts1.splice(i, 1)
          }
github cmdalbem / ciclomapa / src / Storage.js View on Github external
constructor() {
        firebase.initializeApp({
            apiKey: firebaseConfig.apiKey,
            authDomain: firebaseConfig.authDomain,
            projectId: firebaseConfig.projectId
        });

        this.db = firebase.firestore();
    }