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 days ago.
Improve this question
I am new in js, before I was working a bit with c# and entity framework and i found it way easier to manipulate fetched data using LINQ. But right now I don't really grasp how to get access to other table fields in JavaScript.
For example I have 2 tables i SQLite 3.x.x Tickets and users. One user can have many tickets but one ticket only one user. Structure look like that:
Ticket table
User table
Now I am fetching user data and want to retrieve all tickets given user have.
In c# i would normally have access to shadow properties but in my react project it seem to be impossible. Here is a short simplified example of what i want to get
import React from 'react'
import { useState } from 'react'
export const Test = () => {
const [users, setUsers] = useState([])
const usersWithTicket = [{id: 1, email: "john#gmail.com", password: "xxxxxx", roles: "user" },
{id: 2, email: "dohn#gmail.com", password: "xxxxxx", roles: "user" },
{id: 3, email: "fohn#gmail.com", password: "xxxxxx", roles: "user" },
{id: 4, email: "gohn#gmail.com", password: "xxxxxx", roles: "user" }]
setUsers(usersWithTicket)
return (
<div>
{users.map((user) => {
return (
<div>
<h1>{user.ticketid}</h1>
</div>
);
})}
</div>
)
}
I will always get ticket is undefined but tickets and user tables are connected by foreign key. Why can't I access ticket data trough user data? I know I can loop trough tickets and users and merge them together but it feels like not right way to work with fetched data.
Related
I have the following graphQL schema, running on faunaDB
type Form {
name: String!
index: Int!
user: User
formInputVals: [FormInputVal!] #relation
}
type FormInputVal {
name: String!
index: Int!
type: String!
formRoot: Form!
}
type User {
name: String!
email: String!
password: String!
forms: [Form] #relation
}
type Query {
allForms: [Form!]
allUsers: [User!]
allFormInputVals: [FormInputVal!]
}
I'm trying to figure out how I would query and write a mutation where i would update a specific form id and update all the specificed documents related to that form via there id's or what are called references in fauna db.
I can update the form name with this mutation
mutation{
updateForm(id:"291541554941657608",data:{name:"test"}){
name
}
}
but beyond that I can't seem to figure out how to update multiple FormInputVals of the type Form. I talked to faunaDB, and they said I might need a resolver throught there lambda function that allows me to do so, any one familiar with this at all. I have posted another question, but I have changed my end goal in this one, but this question is similar Designing the db and state mutations and requests of a form builder in react with graphQL, faunaDB, nextJS & Apollo
See I have a object from my form that maps to the documents ID's in the collection in fauna DB. It looks like so.
[{"291705061039407629":{"name":"test","type":"text"}},{"291705951034016264":{"name":"test","type":"text"}}]
How would I upate say two matching records in faunaDB for the FormInputVal type. The numbers represent the ID of the document in the collection.
Here's a screenshot of the GraphQL docs for updating a formInputVal, my issue is I want to update multiple documents at once.
and here is the updateForm docs
Update: I have figured out that create option can add multiple documents at a time, just have to figure out if I can update or replace all of them. This is what worked for adding multiple documents at once.
mutation{
updateForm(id:"291541554941657608",data:{
name:"hello",
index:0,
formInputVals:{
create:[
{name:"test", index:0, type:"text"},
{name:"test", index:0, type:"text"},
{name:"test", index:0, type:"text"},
]
}
}){
name
formInputVals{
data{
name
type
index
}
}
}
}
This question already has answers here:
Adding new data to firebase users
(2 answers)
Closed 2 years ago.
Currently I have small project using react native and I am using Firebase as backend. I have registration form with more than two fields (name, phone num, gender, etc), but with Firebase we can only register a user with email and password. So, my question is how I can save other information of user and later how I would retrieve that information?
On your backend you can create 'users' collection and save it after registering a user
const data = {
email: 'email',
password: 'password'
}
firebase.auth().createUser(data)
.then((userRecord) => {
var uid = userRecord.uid;
return firebase.firestore().collection('users').doc(uid)
.set({
user_uid: uid,
gender: '',
...
})
})
and later you can use doc id to retrieve extra information
firebase.firestore().collection('users').doc(uid).get()
I am developing a Node.js application using MongoDB as a database. I have created a collection called users and the structure of it is as below:
{
username: 'Alex',
email: 'alex#test.com',
password: '123456',
cart: {
items: [
{
productId: 574894734,
quantity: 1,
}
],
},
}
When the user clicks on the "add to cart" button, I want to check if the cart already contains the product. If it contains the product I want to increase its quantity otherwise I want to add it.
I've tried a lot of solutions on StackOverflow but I couldn't solve the problem.
I get duplicated items in the cart object.
Help me.
I am trying to add facebook login in my app. And its successfuly working but problem is every time i login with facebook it change the firestore data. Here is my code
onLoginSuccess(res: FacebookLoginResponse) {
const credential = firebase.auth.FacebookAuthProvider.credential(res.authResponse.accessToken);
this.fireAuth.auth.signInWithCredential(credential)
.then((response) => {
console.log(response);
this.fb.api('me?fields=id,name,email,first_name,picture.width(720).height(720).as(picture_large)', []).then(profile => {
this.userData = {email: profile['email'], first_name: profile['first_name'], picture: profile['picture_large']['data']['url'], username: profile['name']}
console.log(this.userData);
console.log(this.fireAuth.auth.currentUser.uid);
let userData = {
email: this.userData.email,
username: this.userData.username,
photo: this.userData.picture,
phone: '',
point : '0',
uID: this.fireAuth.auth.currentUser.uid
};
this.angularFirestore.collection('AppUsers').doc(this.fireAuth.auth.currentUser.uid).set(userData); //Here is the problem
this.router.navigate(["/select"]);
})
});
}
I need to check if there is doc already available with this.fireAuth.auth.currentUser.uid so it will not add in database. IF not avaiable it will store in database.
So i need the method how can i check docID exist or not ?
There are some ways that you can get the information if a document exists on Firestore or not.
On this question of the Community here, there is all the logic for how to create a function to check a single document on the Firestore database - it's in Java, but I believe the logic should help you.
On this other post How can i get single document from Firestore with query (I'm using Ionic 4 ), there is a query to return a single document as well, in case you think this one fits you better.
Let me know if the information helped you!
If your problem is "every time i login with facebook it change the firestore data" you can use "update" instead of "set".
Here is the docs about it: Firestore Update Doc
Is there a way to populate students ?
"cohortStudents": {
"cohort-id-4": {
"cohortId": "cohort-id-4",
"instructorId": "CZVLBcZ7lQe2OUcHdDLjW4OVFaB2",
"students": {
"student-id-1": true,
"student-id-2": true,
"student-id-3": true
}
}
}
So basically i can get data from cohortStudents by
https://[projectname].firebaseio.com/cohortStudents.json?orderBy="cohortId"&equalTo="cohort-id-4"
And i will get object but students: {} will have still student-id-1 etc
Is there a way to get data look like students: { student-id-1: { name: '', email: '' } }
Hope your help
Firebase Database queries read child nodes from a single location only. There is no support for server-side joins.
To get the users that are referenced from students you will have to do a client-side join: loading each user individually.
I highly recommend using a Firebase SDK to do this, since it is optimized for this type of use-case. See my answer to this question for more.