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 3 years ago.
Improve this question
I just cant seem to get the snapshot docs to show me the data from the server.
i have checked the collection. it is called "creaciones" without uppercase. I have 1 document and I have files written already. I've made no spelling mistakes whatsoever. I made this work before and now i cant.
ive tried using function "(querySnapshot){" but i got no positive results
//Setup grilla
const setupGrilla = (data) => {
let html = '';
data.forEach(doc => {
const grilla = doc.data();
const creacion = `
<div>
<img src='jpg/${grilla.tipoCreacion}.png' alt='tipoCreacion'>
<h2>${grilla.nombreCreacion}</h2>
<img src='Imagenes/${grilla.nombreFoto}' alt='nombrefoto' class='imagen'>
<span>piezas: ${grilla.piezas}</span>
<span class='separador'></span>
<span>tiempo: ${grilla.tiempo} minutos</span>
<p>padre: ${grilla.ayuda} </p>
<p class='puntos'>Puntos: ${grilla.puntos} </p>
</div>
`;
html += creacion;
});
}
//get Data
db.collection('creaciones').get().then(snapshot => {
setupGrilla(snapshot.docs);
console.log(snapshot.docs);
});
I expect it to fetch the database data.
I have already given you the answer here
You are passing the wrong argument in your method
db.collection('creaciones').get().then(snapshot => {
setupGrilla(snapshot);
});
And you can find the documentation here
Related
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 1 year ago.
The community reviewed whether to reopen this question 1 year ago and left it closed:
Original close reason(s) were not resolved
Improve this question
I'm new to Firebase and I'm blocked on something. Actually, I've some difficulties reading data from a Firestore Database. My code:
const functions = require("firebase-functions");
const admin = require("firebase-admin");
admin.initializeApp();
const db = admin.firestore();
exports.scheduledFunction = functions.pubsub.schedule("* * * * *").onRun(async () => {
console.log("start");
const querySnapshot = await db.collection("Next_callenges").get();
console.log("Let's see :", querySnapshot);
return null;
});
There is no output except this : "let's see : QuerySnapshot{".
To add some context, the objective behind this code is to get the first data inserted in the first database, add it to a second database and delete it from the first one.
As others have commented, the output you get is exactly what is expected from your code: since you log querySnapshot, you get whatever debug output the QuerySnapshot class defines.
If you want to see the data of each document in that query snapshot, you can do:
querySnapshot.forEach((doc) => {
console.log("Document "+doc.id+":", doc.data());
})
Note that this is just using the Firestore API and has nothing to do with the fact that you use Firestore in Cloud Functions. Since Cloud Functions adds quite some complexity to the case, I'd recommend first learning more about the Firestore API in JavaScript by reading its documentation and following its codelab.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I am currently using an API to create a React Redux application. My problem is I am confused about how to efficiently use the data as the API has more than 14470 "pages" to navigate around. My main goal is to display certain items in the API based on key value pair. For example I would say I want to display a category in the API based on a certain key value pair such as "highestRating" and want to map through the API to find out the five items with the highestRating, how would I be able to do this efficiently?
What I have tried so far is looping to get the entire API available to me but then I get stuck with my current task at hand.
export const fetchHighestRating = () => async dispatch => {
let data = [];
let morePagesAvailable = true;
let currentPage = 0;
while (morePagesAvailable) {
currentPage++;
const response = await api.get(
`/api?page%5Blimit%5D=10&page%5Boffset%5D=${currentPage}`
);
data = [...data , response];
morePagesAvailable = currentPage < 17471;
}
dispatch({ type: FETCH_HIGHEST, payload: data });
};
This is not a javascript problem, it is database. You should run query directly in database to test response speed and decide what to do next, including:
Sharding
Indexing
Optimize config of DB
....
Any above required research in type of DB you are using, the current situation of DB so there is no exactly answer now!
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
this is my firebase database
- conversations (collection)
-- xxx (document)
--- users (collection)
---- xxx (document)
I want to list all the conversations and its users
this.db.collection('conversations').get().then(querySnapshot => {
querySnapshot.docs.forEach(doc => {
console.log(doc.collection('users').get())
});
});
I´m getting doc.collection is not a function
update: this is what I have after getting the id and making a new query. now the question is. is this performant?
this.db.collection('conversations').get().then(conversationsQuerySnapshot => {
conversationsQuerySnapshot.docs.forEach(doc => {
this.db.collection('conversations').doc(doc.id).collection('users').get().then(usersQuerySnapshot => {
usersQuerySnapshot.docs.forEach(doc => {
console.table(doc.data());
});
});
});
});
You're looking for doc.ref.collection('users'), since you need go get from the DocumentSnapshot to its DocumentReference through doc.ref.
Note that I find it easiest to spot such mistakes by simply following the types. Your querySnapshot is a QuerySnapshot, which means that your doc is a QueryDocumentSnapshot. Since QueryDocumentSnapshot doesn't have a collection method, it's easier to figure out what's going wrong.
you would call it: db.collection('conversations').doc({docID}).collection('users')
Your current query is set up to look through every conversation and then get every user in each of those. Plus the second part (getting the users) has no base document to pull from, which is why you're seeing an error.
I recommend watching this video
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 4 years ago.
Improve this question
When a user click's on a username on the list below, it's meant to open up the add user page with the name's of the user in the fields.
I get this error message:
Here's the code in the manage users page:
componentWillMount: function () {
var userId = this.props.params.id; // from the path /user:id
if (userId) {
this.setState({ user: userId.getUserById(userId) });
}
},
Here's the code in the userApi:
getUserById: function(id) {
var user = _.find(users, {id: id});
return _clone(user);
},
I am new to StackOverflow and programming, so if this post doesn't meet the community's guidelines, please guide me on how to better make use this platform so I can further my learning progression.
Thanks,
Rickie
Using the userId variable you can't call your API. Since getUserById is from your API you must call the method from there.
userApi.getUserById(userId);
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 4 years ago.
Improve this question
So I'm having some trouble. I have a map populated from a json file which works perfectly. However the client wants to truncate the description in the pin popup to 300 charters (rather than actually write text that fits). I thought I could change the description in the promise but it's not working, in fact it's having no effect at all. If anyone has an idea how to do this I'd really appreciate it.
fetch('/assets/map/markers.json')
.then(response => {
if (response.ok) {
return response.json();
}
throw new Error('Network response error.');
})
.then(charData => {
let mapData = charData.map(item => item.description.split(0, 300).join(" "));
createMap(mapData);
})
.catch(error => {
console.log('There has been a problem: ', error.message);
});
To take some characters out from a string you can use String.prototype.substring().
So change
item.description.split(0, 300).join(" ")
To
item.description.substring(0, 300)