-
let say i have this collection. //the collection sample
//parent collection here
stores = [
{
"some cuid": {
"some props": "hello",
// child collction
products: [
{
"some cuid": {
//some props
},
},
],
},
},
]
//for example
db.ref("stores/some cuid").child('stores').push({
// some props
}) how do i query products. i mean want to get all products. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 6 replies
-
Hi, I'm not really sure what you are trying to do here? 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 product = productSnapshot.val(); // { "title": "Product 1" }
});
// Or, do it yourself by getting .val()
const products = productsSnapshot.val(); // { "somecuid1": { "title": "Product 1" }, "somecuid2": { "title": "Product 2" } } If you want to query (instead of getting all), use const querySnapshots = await db.ref('products')
.query()
.filter('title', '>', 'Product')
.get() See documentation for more info. |
Beta Was this translation helpful? Give feedback.
-
@appy-one Yay. I missed some part of the documentation. So its not suggested to store array on nested object if it's frequently updated. I thought I can query from an array inside a nested object. just like I imagined. I have to do the manual mappings after all. I should have put this to discussion tab maybe. Thanks for the fast reply anyway. |
Beta Was this translation helpful? Give feedback.
-
Are you going to implement after and before hooks on the acebase-server? just like on fastify |
Beta Was this translation helpful? Give feedback.
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:
If you want all products you previously stored, simply get the value: