const db = firebase.firestore();
const FieldValue = firebase.firestore.FieldValue;
const myUserID = '123456';
await db.collection('posts').add({
title: 'Hello world!',
postedBy: myUserID,
likedBy: {},
likes: 0,
})
const post = await db.collection('posts').doc('test').get();
const hasLiked = post.likedBy[myUserID] === true
await db.collection('posts').doc('test').update({
likes: FieldValue.increment(1),
[`likedBy.${myUserID}`]: true,
})
await db.collection('posts').doc('test').update({
likes: FieldValue.increment(-1),
[`likedBy.${myUserID}`]: FieldValue.delete(),
})