how can we get the docs in users collection in firebase [closed] - javascript

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
i want to create an array from data coming from firestore.
the structure is as follows
users(collection)>uid1(doc)>(profile)>uid2(doc)>data
now the uid is dynamic as for every element of users collection. i want to create an array for every element with data
eg
[
{data},
{data},
.....
]
i have written the code for single uid
db.collection('users').doc("BbXn5M213XSKNfcSAR2MvbjPD403").collection("profile").onSnapshot((snapshot) => {
console.log(snapshot.docs.map(doc => doc.data()));
});
here are some firebase screenshot
screenshot 1 screenshot 2 here

I think what you'd looking for might be a collection group query, which is a way to get contents from all collections with a specific name.
So in your example this would be the way to get all documents from all data (sub)collections:
db.collectionGroup("profile").onSnapshot((snapshot) => {
console.log(snapshot.docs.map(doc => doc.data()));
});

Related

Firebase reference objects by ID [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 months ago.
Improve this question
Imagine I have 2 collections: musicians and albums. Is there a chance I can reference albums with musicians by ID so that musicians can have multiple albums and appear as an array for musicians? What would the query look like in Firebase 9 Firestore? For example, this is possible and achievable in MongoDB. What are the chances of referencing 2 collections in Firebase? I am looking forward to achieving something like a Database Reference in MongoDB
You can use the Reference field type to add a reference to a document in a field. To use this, create a DocumentReference object for the destination:
const artistReference = doc(db, "artists", "beatles");
And then set this as the value of a field:
const songRef = doc(db, "songs", "get back");
await setDoc(songRef, {
title: "Get back",
artist: artistReference
});
Note that no referential integrity checks are performed by Firestore, so the above does not check whether the artist document exist - nor will it prevent deleting the artist document.

Iterate over array in proxy [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 months ago.
Improve this question
Good day.
I was testing stuff in Javascript with Proxies.
Currently I have this proxy
My question was, how do I iterate over this? I've tried several methods, including object.keys and forEach, which yielded nothing.
Thanks in advance
You need to specify an ownKeys method in the handler you're using to create the proxy or you won't be able to enumerate the keys of the proxy object.
const obj = { test: 'a' };
const handler1 = {
ownKeys(target) {
return Reflect.ownKeys(target);
}
};
const proxy1 = new Proxy(obj, handler1);
console.log(Object.keys(proxy1)) // ['test']
Edit
Actually, you can use Reflect.ownKeys directly also, but you'll want to make sure the behavior is what you expect. For example, it might return length as a key as well.

Display specific row from API in react [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 months ago.
Improve this question
Iam trying to write a map function to show all the item in API
ScreenShoot of code to display the items
and this is the console log of the item that fetch from API
I got Error for the map function that isn't working what is the solution
Thank you
It's a little hard to tell from the picture.
But if I understood correctly you have no return.
Note that you can only have one div in the return.
export default function Feed(props) {
const array1=props.graphDataa.value
return (
<div>
{
postsArr.map(item=> (whatever you want to display...))
}
</div>
Your div is closed in the opening tag - "taskcolorblack-div"
You need return value from method listmap like this: return map1;
In render function u can call like this return (<>{listmap().join()}</>)

Retrieving specific objects from a Fetch API (JavaScript) - Re post [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
Edited question: Trying to write the code needed to display only the title and description of the book returned.
I have attempted the following, and am met with a response of, "Cannot read property 'title' of undefined." The same happens to 'description'(line 6) when line 5 is removed.
require('isomorphic-fetch');
let items = [];
fetch("https://www.googleapis.com/books/v1/volumes?q=isbn:0747532699")
.then(res => res.json())
.then((result) => {
items = result.items;
console.log(items.volumeInfo.title)
console.log(items.volumeInfo.description)
}),
(error) => {
console.log(error);
}
What am I doing wrong, and how can I fix it?
items is an array. You would need to access it like this:
result.items[0].volumeInfo.title
More specifically, you could loop the results
for (let i = 0 in items) {
result.items[i].volumeInfo.title; //do something here
}
The issue here is result.items is actually an array not an object. Thus we can not simply call volumeInfo property on an array. If you want first array values then you can simply do:
const items = result.items;
if(items && items.length){
console.log(items[0].volumeInfo.title)
console.log(items[0].volumeInfo.description)
}
Or, if you want the info from all the items, then you can loop over it like:
const items = result.items;
items.forEach(function(obj,index){
console.log(obj.volumeInfo.title)
console.log(obj.volumeInfo.description)
});

add and remove html elements to jquery variable [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
i have a JS variable like this:
var elmnts = $('#elm1, elm2, #elm3, #elm4')
how can i add and remove other html elements?
i try this code but there is no result.
elmnts.add('#elm5');
elmnts.remove('#elm1')
$.fn.add returns new collection, it doesn't modify original one. So you should use this syntax.
elmnts = elmnts.add('#elm5');
To remove element from a collection of jQuery objects you can use $.fn.not method:
elmnts = elmnts.not('#elm1');
You should not use remove for this, it's used to delete element from DOM tree.

Categories

Resources