question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

question: take result of first read and use it to fetch additional data

See original GitHub issue
import React from 'react';
import { compose } from 'redux';
import { connect } from 'react-redux';
import { firestoreConnect } from 'react-redux-firebase';

{ ... }

const mapStateToProps = state => {
    return {
        transactions: state.firestore.ordered.transactions,
    }
}

export default compose(
    connect(mapStateToProps),
    firestoreConnect([
        { collection: 'transactions', limit: 10, orderBy: ['createdAt', 'desc']}
    ]),
)(Listing);

What is the current behavior? I store uids of users inside of each transaction document with the intention of building a nested document for each transaction containing the transaction information and user information in one object per transaction. Is this possible and if so what approach would you recommend? Usually, when using sagas I would just resolve the document first then make a second read for the particular user document. Unsure how to do this with firestoreConnect though.

What is the expected behavior?

  1. Get 10 most recent transactions
  2. Each transaction contains a uid to a user in the /users/ collection
  3. For each transaction, take that uid and merge the relevant user document into the transaction object

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
prescottpruecommented, Nov 8, 2018

Population support was released as part of v0.6.0-alpha.3 (make sure to install from the next tag, not latest)

Here are the docs: https://github.com/prescottprue/redux-firestore/tree/next#population. It is basically a direct port over from react-redux-firebase, so the populate docs for that may be helpful

Seems like you are looking for something like:

import { firestoreConnect, populate } from 'react-redux-firebase'

const populates = [{ child: 'uid', root: 'users' }] // uid parameter from /users collection
const collection = 'transactions'

export default compose(
    firestoreConnect([
        { collection, limit: 10, orderBy: ['createdAt', 'desc'], populates }
    ]),
    connect((state) => ({
      transactions: populate(state.firestore, collection, populates)
    })),
)(Listing);

Let me know if it doesn’t work as expected and we can reopen

1reaction
iFallUpHillcommented, Nov 8, 2018

@prescottprue Works perfectly for me 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

How To Use the JavaScript Fetch API to Get Data - DigitalOcean
In this tutorial, you will create both GET and POST requests using the Fetch API.
Read more >
Fetch data in database always display first record
If the result of 'OleDbCommand.ExecuteReader' is multiple rows. You must call OleDbDataReader.Read() multiple. example: while (reader.
Read more >
Using the Fetch API - MDN Web Docs
The simplest use of fetch() takes one argument — the path to the resource you ... with the result of parsing the response...
Read more >
Python cursor's fetchall, fetchmany(), fetchone() to ... - PYnative
First understand what is the use of fetchall, fetchmany(), fetchone(). cursor.fetchall() fetches all the rows of a query result.
Read more >
How to Use the JavaScript Fetch API to Get Data?
Approach: First make the necessary JavaScript file, HTML file and CSS file. Then store the API URL in a variable (here api_url). Define...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found