Giter Site home page Giter Site logo

Comments (14)

prescottprue avatar prescottprue commented on May 19, 2024 1

@SUPERTEMPO you should try making a storeAs that contains that id such as

storeAs: `${props.postId}-postLikes`

from redux-firestore.

compojoom avatar compojoom commented on May 19, 2024

Hm, maybe I missunderstood the docs:
{ collection: 'cities', doc: 'SF', subcollections: [{ collection: 'zipcodes' }] },

thought that this would get me the cities/SF + cities/sf/zipcodes?
but it seems that if I want the doc cities/SF - I should just do another call?

Is this the correct behavior?

from redux-firestore.

prescottprue avatar prescottprue commented on May 19, 2024

@compojoom That is correct behavior currently, but I have noticed this means repeating myself in a few places.

What are your thoughts on the potential of an option on the query to get both the document and the subcollection? Under the hood it would be two queries, but it might mean much less repeating ourselves.

Maybe something like:

{
  collection: 'cities',
  doc: 'SF',
  includeDoc: true, // <- this option, but maybe a different name?
  subcollections: [{ collection: 'zipcodes' }]
}

from redux-firestore.

compojoom avatar compojoom commented on May 19, 2024

Well, actually - once you know that you can't do it in one go it's a no-brainer. Maybe we should change the docs and mention this behavior?
You can't fetch a document and it's collection directly in firestore anyway... So what you have here seems consistent.

from redux-firestore.

Sgiath avatar Sgiath commented on May 19, 2024

Hi I have slightly different problem. I figure it out that i need to do multiple queries to get document with his subcollections. So I did something like this:

firestoreConnect((props) => [
    { collection: 'games', doc: props.match.params.id },
    { collection: 'games', doc: props.match.params.id, subcollections: [{ collection: 'teams' }] },
    { collection: 'games', doc: props.match.params.id, subcollections: [{ collection: 'tasks' }] },
  ])

And it works correctly for firestore.data I have there:

{
  "firestore": {
    "data": {
      "games": {
        "xxx": {
          "name": "Game name",
          "teams": {
            "xxxx": {"name": "Team 1", "password": "pswd1"},
            "yyyy": {"name": "Team 2", "password": "pswd2"},
          },
          "tasks": {
            "xxxx": {"name": "Task 1", "hint": "Hint 1"},
            "yyyy": {"name": "Task 2", "hint": "Hint 2"},
          },
        },
      },
    },
  },
}

But for firestore.ordered the data are rewritten instead of compose together (only tasks are there - the last query):

{
  "firestore": {
    "ordered": {
      "games": [
        { "name": "Task 1", "hint": "Hint 1", "id": "xxxx", },
        { "name": "Task 2", "hint": "Hint 2", "id": "yyyy", },
      ],
    },
  },
}

The workaround is to use storeAs but then I have this structure:

{
  "firestore": {
    "data": {
      "games": {},
      "teams": {},
      "tasks": {},
    },
    "ordered": {
      "games": [],
      "teams": [],
      "tasks": [],
    },
  },
}

Is this a bug or intended behavior?
Is there some other workaround for this?

from redux-firestore.

prescottprue avatar prescottprue commented on May 19, 2024

@Sgiath What you are mentioning should no longer be an issue in the most recent versions. There was an issue in the ordered reducer which was fixed. Can you confirm?

from redux-firestore.

JoshSum avatar JoshSum commented on May 19, 2024

hi guys i wanna ask,,,,can we change this option to a local state? Thx for any help

firestoreConnect([
        {
            collection: 'campaignModules',
            doc: 'G7N0CX17W70830A'   // <- this option,can be replace with local state?
            , subcollections: [{ collection: 'daily', doc: fullDate }], storeAs: 'daily'
        }
    ])

from redux-firestore.

compojoom avatar compojoom commented on May 19, 2024

@JoshSum - before firestoreConnect is called - your redux selector is being executed. So if in the selector you return {docId: myDocId}

and you change your firestore connect to accept props as first argument, then you can access prop.docId

firestoreConnect(props => {
const {docId} = props
return [
collection...
doc: docId
...
]
})

from redux-firestore.

JoshSum avatar JoshSum commented on May 19, 2024

@compojoom I have many documentId on each subcollection.... how to check if exist, then firestoreconnect, if not exist dont do firestoreconnect, but i have default connect on top of this....

firestoreConnect(props =>{
const daily = props.name
return[
        { collection: 'users' }, // <- this default connect
        { collection: 'campaignModules' }, // <- this default connect
        {
            collection: 'campaignModules',
            doc: daily // <- not always exist,,, if user click it exist, how to avoid error before user click
            , subcollections: [{ collection: 'daily', doc: fullDate }], storeAs: 'daily'
        }
    ]})
)(AdsLocation)

from redux-firestore.

compojoom avatar compojoom commented on May 19, 2024
firestoreConnect(props =>{
const daily = props.name
// No daily, no need to subscribe to any document in firestore
if(!daily) {
return []
}
return[
        { collection: 'users' }, // <- this default connect
        { collection: 'campaignModules' }, // <- this default connect
        {
            collection: 'campaignModules',
            doc: daily // <- not always exist,,, if user click it exist, how to avoid error before user click
            , subcollections: [{ collection: 'daily', doc: fullDate }], storeAs: 'daily'
        }
    ]})
)(AdsLocation)

from redux-firestore.

techfortified avatar techfortified commented on May 19, 2024

@compojoom and @prescottprue ....Please how can i automatically query a collection and its subcollection without knowing the doc id of each document? I have a collection and subcollection with different documents but i want to return each collection with its subcollection in single query. How do i go about it in react-redux-firestore?? e.g supaPosts is a collection with supaPostLikes as subcollection, so the idea now is to fetch each doc from supaPosts and use the doc id each of supaPosts to query its subcollection and return if the currentUserId is present in each supaPosts subcollection supaPostLikes... Here is the nature of my database model
supaPosts collection and supaPostLikes subcollection

data-model

now am trying something like this....

`firestoreConnect((props) => {
        return [
        { collection: 'supaPosts',orderBy:['supaPostTime','desc'],limit:10 },
        { collection: 'supaPosts', doc: **something**, subcollections: [{ collection: 'supaPostLikes' },where[
    ['likerId', '==', **currentUserId**]
  ]}
      ]
    })`

Now how do i get the doc id called something of each supaPosts document and use it to query its subcollection supaPostsLikes and return if likerId is equal to currentUserId?? Or it is not possible to do so

from redux-firestore.

prescottprue avatar prescottprue commented on May 19, 2024

@SUPERTEMPO That would be creating one query then another query, so first the query for all of the posts, then a query for each post to get the likes.

It would probably be best to do this using the multiple levels of your components as a way to structure your listeners:

Structure

SupaPosts - creates listener for supaposts with limit 10
  connect mapStateToProps (`firestore.ordered.supaposts -> props.supaposts`)
  map over items and pass id as `postId` prop and render SupaPost
    SupaPost - creates a listener for the likes of the supapost based on `postId`

Listeners
SupaPosts

firestoreConnect((props) => {
  return [
    { collection: 'supaPosts', orderBy: ['supaPostTime', 'desc'], limit:10 }
  ]
})

SupaPost

firestoreConnect((props) => {
  return [
    {
      collection: 'supaPosts',
      doc: props.postId,
      subcollections: [
        {
          collection: 'supaPostLikes',
          where: [
            ['likerId', '==', **currentUserId**]
          ]
        }
      ]
    }
  ]
}))

from redux-firestore.

techfortified avatar techfortified commented on May 19, 2024

@prescottprue i did exactly as you have written but rather this query

firestoreConnect((props) => {
return [
{
collection: 'supaPosts',
doc: props.postId,
subcollections: [
{
collection: 'supaPostLikes',
where: [
['likerId', '==', props.uid]
]
}
]
}
]
})

is picking just the first props.postId and returning multiple times for the number of limit i have which is 10 and even overwriting the supaPosts state. when i tried to use storeAs postLiked, it is returning but still multiple data for only the first props.postId. Dunno what to do.... dunno if there is any way round .......thanks

from redux-firestore.

techfortified avatar techfortified commented on May 19, 2024

@prescottprue thanks man.... You are great..... it worked perfectly.....thanks so much.... You really saved me, keep doing the good work.....

from redux-firestore.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.