In sign up part I created the user like this:
**_authService
.createPerson( //for sign up
_userNameTextController.text,
_userSurnameTextController.text,
_emailTextController.text,
_passwordTextController.text,
birth,
dropdownValue,
_addressTextController.text)
.then((value)**
but I can't update the data of the user. I tried to update like that:
firestoreInstance.collection("Person").doc(userData.uid).update({
"userName" : _userNameTextController.text,
"userSurname" :_userSurnameTextController.text,
"country" : _addressTextController.text,
"birth" :birth,
"gender" :dropdownValue
}).then((value)
What should i do?
It looks like you trying to add a new field 'country'. You can add a new field using set() with merge true.
firestoreInstance.collection("Person").doc(userData.uid).set({
"userName" : _userNameTextController.text,
"userSurname" :_userSurnameTextController.text,
"country" : _addressTextController.text,
"birth" :birth,
"gender" :dropdownValue,
}
}, SetOptions(merge: true))
Related
I want to save users data in firebase , should I save theme as map in database like this:
[
{
"id":1
"name":"ab"
"age" : 34
}
{
"id":2
"name":"aab"
"age" : 4
}
{
"id":3
"name":"aeb"
"age" : 25
}
]
or there better idea to do that?
I would suggest use FireStore for such data.
These types of incremental approaches aren't possible in firebase firestore. Alternatively, you can use a firebase function to add id while creating a new user. When a new document has been created the function will call the previous user-id as an integer and increment the id number by 1 and post it as the next user-id. But if you want to have the feature to delete the user document in the future then the id will be also removed as usual.
I am very beginner to AWS DynamoDB, I want to scan the DynamoDB with SENDTO.emailAddress = "first#first.com" as FilterExpression.
The DB Structure looks like this
{
ID
NAME
MESSAGE
SENDTO[
{
name
emailAddress
}
]
}
A Sample Data
{
ID: 1,
NAME: "HELLO",
MESSAGE: "HELLO WORLD!",
SENDTO: [
{
name: "First",
emailAddress: "first#first.com"
},
{
name: "Second",
emailAddress: "second#first.com"
}
]
}
I want to retrieve document that match emailAddress. I tried to scan with filter expression and here is my code to retrieve the data. I am using AWS Javascript SDK.
let params = {
TableName : "email",
FilterExpression: "SENDTO.emailAddress = :emailAddress",
ExpressionAttributeValues: {
":emailAddress": "first#first.com",
}
}
let result = await ctx.docClient.scan(params).promise();
In order to find the item by sendto attribute, you need to know both name and emailAddress attribute value. DynamoDB can't find the data by just one of the attributes in an object (i.e. email attribute value alone).
CONTAINS function can be used to find the data in List data type.
CONTAINS is supported for lists: When evaluating "a CONTAINS b", "a"
can be a list; however, "b" cannot be a set, a map, or a list.
Sample code using Contains:-
var params = {
TableName: "email",
FilterExpression: "contains (SENDTO, :sendToVal)",
ExpressionAttributeValues: {
":sendToVal": {
"name" : "First",
"emailAddress" : "first#first.com"
}
}
};
If you don't know the value of name and emailAddress attribute, you may need to remodel the data to fulfill your use case.
I think that you should create two tables for users and for messages.
The user table has partition_key: user_id and sort_key: email and a field with an array of his messages ids.
The message table has partition_key: message_id and a field with an array of users ids.
When you will get the array of users ids you can use BATCH GET query to get all users of one message.
When you will get the array of message ids you can use BATCH GET query to get all messages of one user.
If you want to get one user by email you can use QUERY method.
Docs
I´m trying to get data from Firebase depending on the name and city from object.
My firebase tree looks like this:
MYAPP
Object:
- 12837291ß2837(a random ID):
"name": "test"
"city": "Hong Kong"
- 12382133193u2:
"name": "test"
"city": "Paris"
- 2137829128738:
"name": "test2"
"city": "Frankfurt"
So for example i just want to get the Object where the name is "test" and the city is "Hong Kong".
i tried sth like this but i dont get any Data:
let ref = FIRDatabase.database().referenceFromURL("https://myRef")
ref.queryOrderedByChild("Object").queryEqualToValue("test").observeEventType(.ChildAdded) { (snapshot) in
print(snapshot)
}
I also added rules in Firebase like :
".indexOn": "Object"
Two main problems:
your query doesn't match your data structure
you can only filter on one property.
Your query doesn't match your data structure
To sort/filter you first specify the property that you want to filter on and then the filtering operation. Since the value you specify is from the name property, the correct query is:
let ref = FIRDatabase.database().referenceFromURL("https://myRef")
let query = ref.queryOrderedByChild("name").queryEqualToValue("test")
query.observeEventType(.ChildAdded) { (snapshot) in
print(snapshot)
}
You can only filter on one property
Firebase Database only supports ordering/querying on a single properties. See Query based on multiple where clauses in firebase.
I have something strange with a piece of code.
I have interventions and each intervention is associated to a customer. Then, in my interventions list template I use:
{{pathFor 'editCustomer' customer}} where customer is the customer _id.
If I print {{customer}} I get vFJHY2CtLi4GC7T5h but the link contains ueYXhWGL6mG3Cbq3v
ueYXhWGL6mG3Cbq3v corresponds to intervention _id
So the link is wrong beacause the id parameter is not that from the customer but the intervention
The document looks like:
{ "_id" : "ueYXhWGL6mG3Cbq3v", "title" : "intervention#1", "priority" : "medium", "customer" : "vFJHY2CtLi4GC7T5h", "assignedTo" : "97xzchCuSQGduz5vR", "issue" : "pokpokpok", "author" : "97xzchCuSQGduz5vR", "createdAt" : ISODate("2016-02-04T06:47:28.033Z") }
My router for customer id is:
Router.route('/customers/:_id', {
name: 'editCustomer',
data: function() {
return Customers.findOne(this.params._id);
}
});
An idea ?
Try to use
{{#with Customer}}
to set the data context just before
{{pathFor 'editCustomer' }}
The solution was to prefix the value with _id= like proposed by Łukasz Kapica
So: {{pathFor 'editCustomer' _id=customer}}
Thanks Łukasz Kapica
I am having trouble deleting a single item from a list. I want to delete the 'oldest' item, and these have been added via the .push() method. It seemed pretty straightforward to do this but I am having issues. For my data structure, please see below. I am sure I am just doing something dumb as this must be a common use-case.
Any ideas/feedback would be greatly appreciated.
Code:
firebase.child('articlesList').orderByChild('site').equalTo('SciShow').limitToFirst(1).once('value', function(snapshot){
// This was one try, This seems to remove the entire articleList
snapshot.ref().remove();
// I have also tried this, and this seems to do nothing at all
snapshot.forEach(function(dataSnapshot){
dataSnapshot.ref().remove();
});
});
Data Structure:
"articlesList" : {
"-Jc16JziK668LV-Sno0s" : {
"id" : "http://gdata.youtube.com/feeds/api/videos/c8UpIJIVV4E",
"index" : "SciShow",
"link" : "http://www.youtube.com/watch?v=c8UpIJIVV4E&feature=youtube_gdata",
"site" : "SciShow",
"title" : "Why Isn't \"Zero G\" the Same as \"Zero Gravity\"?"
},
"-Jc16Jzkn6q41qzWw3DA" : {
"id" : "http://gdata.youtube.com/feeds/api/videos/Wi9i8ULtk4s",
"index" : "SciShow",
"link" : "http://www.youtube.com/watch?v=Wi9i8ULtk4s&feature=youtube_gdata",
"site" : "SciShow",
"title" : "The Truth About Asparagus and Your Pee"
},
"-Jc16Jzkn6q41qzWw3DB" : {
"id" : "http://gdata.youtube.com/feeds/api/videos/J7IvxfcOkmM",
"index" : "SciShow",
"link" : "http://www.youtube.com/watch?v=J7IvxfcOkmM&feature=youtube_gdata",
"site" : "SciShow",
"title" : "Hottest Year Ever, and Amazing Gecko-Man Getup!"
},
The folks over at Firebase answered this for me on their Google Group. I figured I would post for others to use.
= = =
Hey Ryan,
You are close! Instead of using the value event, you want to use the child_added event. The value event will get fired once with all the data at your /articlesList/ node. That is why you are seeing it delete the whole list. If you use the child_added event, it will fire for each child. Or, if you limit it like you did, it will only fire for a subset of children. One other thing to change is to use limitToLast(1) instead of limitToFirst(1) to get the last child.
Here's the code:
firebase.child('articlesList').orderByChild('site').equalTo('SciShow').limitToLast(1).once('child_added', function(snapshot){
snapshot.ref().remove();
});
Jacob