Skip to content

Querying on children #9

Answered by appy-one
paradis-A asked this question in Q&A
Feb 16, 2021 · 3 comments · 6 replies
Discussion options

You must be logged in to vote

Hi, I'm not really sure what you are trying to do here?
First of all, you are mixing arrays and object collections. Only use arrays for small collections of data that do not change frequently, use object collections for all other situations.

If you want to maintain a collection of products, do this:

db.ref('products').push({ title: 'product 1' }); // Add product to object collection
db.ref('products').push({ title: 'product 2' }); // Do it again

If you want all products you previously stored, simply get the value:

const productsSnapshot = await db.ref('products').get();

// Iterate all objects in the collection with snapshot.forEach:
productsSnapshot.forEach(productSnapshot => {
   const p…

Replies: 3 comments 6 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by paradis-A
Comment options

You must be logged in to vote
2 replies
@appy-one
Comment options

@appy-one
Comment options

Comment options

You must be logged in to vote
4 replies
@appy-one
Comment options

@paradis-A
Comment options

@appy-one
Comment options

@appy-one
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #7 on February 16, 2021 13:24.