Many-to-Many Model and query a many-to-many relationship

This lesson is available for PRO members or as a single course purchase. Sign-in and choose a plan below.
Get Unlimited PRO Access

OR


*Enrollment provides full access to this course (and updates) for life.

file_type_js_official firestore.js
const authorId = 'dr-seuss';
const bookId   = 'lorax';

// 7. Middle Man Collection
const userReviews = db.collection('reviews').where('author', '==', authorId);
const bookReviews = db.collection('reviews').where('book', '==', bookId);

// Single read with composite key
const specificReview = db.collection('reviews').doc(`${bookId}_${authorId}`);


// 8. Map
// Reviews embadded on books
const bookWithReviews = db.collection('books').doc(bookId);
const userReviews = db.collection('books').orderBy('reviews.jeff-delaney');


// 9. Array
const books = db.collection('books').where('categories', 'array-contains', 'fiction');



// 10. Bucket
// Get a collection of documents with an array of IDs

const getLikedBooks = async() => {

    // Get books through user likes
    const userLikes = await db.collection('likes').orderBy('jeff-delaney').get();
    const bookIds = userLikes.docs.map(snap => snap.id);

    const bookReads = bookIds.map(id => db.collection('books').doc(id).get() );
    const books = Promise.all(bookReads)
}


getLikedBooks()

Questions?

Ask questions via GitHub below OR chat on Slack #questions