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.
Improve this question
I wanted to know how to add a field in a certain user uid
So I'd like to add another field like Address for the currentUser "Rowan Whitethorn". How can I do this?
Currently, i could add another field but it creates another documents.
const userRef = firestore.collection('users').doc(currentUser.uid);
async function addAddress() {
const res = await userRef.set({
'Address' : 'Ayala'
}, { merge : true});
}
Firestore documentation describes a feature "merge", where you would typically create a new doc with using ".set", but then pass a parameter "merge" which tells firebase not to overwrite your doc data, in your case it would be something like:
const userRef = db.collection('users').doc(doc_id);
const res = await userRef.set({
'some_new_field': 'value'
}, { merge: true });
Here's the link for their documentation, you will find a similar example under "merge": https://firebase.google.com/docs/firestore/manage-data/add-data
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 2 years ago.
Improve this question
In my Flutter app, I want sorted data to depend upon the last date which is present in medicine list for a particular user, so how can I write my Firebase query?
I'm using Firebase Firestore.
Try something like this (code has not yet been tested):
List<dynamic> getMedicinesSorted() async {
final snapshot = await FirebaseFirestore.instance
.collection('users/tnzdrlpLD1hfJJ6o8iMV/MedicinesList')
.get();
final sorted = snapshot.docs.sort((docA, docB) =>
new DateTime.fromMicrosecondsSinceEpoch(docA.data()['Last_Date']).compareTo(
new DateTime.fromMicrosecondsSinceEpoch(docB.data()['Last_Date'])
)
);
return sorted;
}
[enter image description here][1]
image
[1]: https://i.stack.imgur.com/C6qy8.jpg
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 2 years ago.
Improve this question
I have json format data that I am retrieving from my ORDS server and it looks like this:
{"items":[{"cust_code":"C00013","cust_name":"Holmes","cust_city":"London
","working_area":"London","cust_country":"UK","grade":2,"opening_amt":6000,"receive_amt":5000,"payment_amt":7000,"outstanding_amt":4000,"phone_no":"BBBBBBB","agent_code":"A003
"},{"cust_code":"C00001","cust_name":"Micheal","cust_city":"New York
","working_area":"New
York","cust_country":"USA","grade":2,"opening_amt":3000,"receive_amt":5000,"payment_amt":2000,"outstanding_amt":6000,"phone_no":"CCCCCCC","agent_code":"A008
"},{"cust_code":"C00020","cust_name":"Albert","cust_city":"New York
","working_area":"New
York","cust_country":"USA","grade":3,"opening_amt":5000,"receive_amt":7000,"payment_amt":6000,"outstanding_amt":6000,"phone_no":"BBBBSBB","agent_code":"A008
"},{"cust_code":"C00025","cust_name":"Ravindran","cust_city":"Bangalore
","working_area":"Bangalore","cust_country":"India","grade":2,"opening_amt":5000,"receive_amt":7000,"payment_amt":4000,"outstanding_amt":8000,"phone_no":"AVAVAVA","agent_code":"A011
"},{"cust_code":"C00015","cust_name":"Stuart","cust_city":"London
","working_area":"London","cust_country":"UK","grade":1,"opening_amt":6000,"receive_amt":8000,"payment_amt":3000,"outstanding_amt":11000,"phone_no":"GFSGERS","agent_code":"A003
"}],"hasMore":false,"limit":25,"offset":0,"count":5,"links":[{"rel":"self","href":"http://localhost:9000/ords/demo/customers/getAll/"},{"rel":"describedby","href":"http://localhost:9000/ords/demo/metadata-catalog/customers/getAll/"},{"rel":"first","href":"http://localhost:9000/ords/demo/customers/getAll/"}]}
so I was wondering if there is a way to to break down the items part and to put it in a tables using anguler.
I tried to use this way in my ts file:
http.get('http://localhost:9000/ords/demo/customers/getAll/')
.subscribe(data => this.items = data);
But I keep getting this error:
Error: Error trying to diff '[object Object]'. Only arrays and iterables are allowed
The array you want is in the items property so you have to do
http.get('http://localhost:9000/ords/demo/customers/getAll/')
.subscribe(data => this.items = data.items);
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 years ago.
Improve this question
I want to store the following data in Firebase and use the same in Ionic 3 but I did not find any clear documentation that could help me. Can someone give me a way?
This is an example of array on home.ts
initializeItems() {
this.items = [
{id: '1', nome:'Abaéte', rua:'Moacir', cidade:'Capão da Canoa', bairro:'Centro', numero:'396', ano:'1964', aptos:'55', adm:'Adsel', zelador:'Hugo', contato1:'(51) 0 0000 - 0000', contato2: '(51) 0000 - 0000', imagem:'assets/img/Abaete-min.jpg'},
];
And this a image the App list
Your sample shows an object not an array. Yes you can push objects to Firebase.
I'm assuming you're using angularfire2 with Ionic.
const myObject = {
id: '1',
nome:'Abaéte',
rua:'Moacir',
cidade:'Capão da Canoa',
bairro:'Centro',
numero:'396',
ano:'1964',
aptos:'55',
adm:'Adsel',
zelador:'Hugo', c
ontato1:'(51) 0 0000 - 0000',
contato2: '(51) 0000 - 0000',
imagem:'assets/img/5yDViHGwTkaJSEDkHyqS_Abaete.JPG'
}
this.db.list('/some/path').push(myObject)
.then(resp => {
console.log('All Saved!');
});
If you do want to push arrays you should take a look at the Firebase Blog. It discourages saving arrays, but instead using the push method to generate a unique ID for each array item.
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 5 years ago.
Improve this question
I want to save houses in an array using AsyncStorage. Each array element represents a house Object. And each house object has a latitude, longitude and a house number. I am not sure how to go about representing this. It seems to me that AsyncStorage is not well-suited for saving dynamic objects that can be updated programmatically.
I want to be able to add more houses and delete some houses. Basically what I am trying to do is bookmark some houses and delete them from the bookmarks when the user clicks.
Can anyone help ?
AsyncStorage is absolutely perfect for this.
Starting with the structure of your houses, I would create an Array which stores objects representing an individual house.
const houses = [
{
number: 1,
latitude: 51.5033,
longitude: -0.119519
}
]
Saving to AsyncStorage
When you want to write your collection to AsyncStorage, you would do so like this:
AsyncStorage
.setItem('#houses', JSON.stringify(houses))
.then(houses => console.log(houses)
static setItem(key: string, value: string, callback?: ?(error: ?Error) => void)
You can also use async/await if your project is set up to support it.
Reading from AsyncStorage
Reading your collection back from AsyncStorage is simply done via:
AsyncStorage
.getItem('#houses')
.then(houses => console.log(JSON.parse(houses)))
You could set the response in your state, do as you please.
Deleting a specific house
This depends entirely on how you set your app up. Are you going to map through each house and create a list component for example?
(Sorry about losing the border on the right)
If so, you could:
houses.map(house => (
<View>
<Text>Number: {house.number}</Text>
<Text>Latitude: {house.latitude}</Text>
<Text>Longitude: {house.longitude</Text>
<Button onPress={() => this.deleteHouse(house.number)}/>
</View>
));
Then create a deleteHouse function which will handle it.
const deleteHouse = (number) => {
const { houses } = this.state; // Assuming you set state as previously mentioned
const newHouses = houses.filter((house) => house.number != number);
this.setState({houses: newHouses}, () => saveHouses);
}
And finally a saveHouses to sync it back to AsyncStorage. The function will clear AsyncStorage and then save the new houses.
const saveHouses = () => {
const { houses } = state;
AsyncStorage
.removeItem('#houses')
.then(() => {
AsyncStorage
.setItem('#houses', JSON.stringify(houses))
.then(houses => console.log(houses)
});
}
You need a Sqlite alternative like Realm, it's free, fast and easy to code, with this you will save tons of hours of work, also as you need, you can make queries, update and delete objects.
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 8 years ago.
Improve this question
I have 2 select boxes in my app and they are populated from db, when I choose a value from first select box, second select box is populate via ajax. this scenarion works great. but as the values in select boxes are static I didn't want populate them from db, I think use for this a file is more usefull and good for app performance. so how I can populate them from file (json, xml, etc.)? first select box to the second is one-to-many
This sounds like a lot of work since your going to have to populate the text files from db. Infact its end result will be in effect no different to a caching solution.http://mrdustmite.blogspot.co.uk/2010/09/simple-ehcache-in-grails.html?m=1
The mentioned plugin above generates primary/secondary values from as JSON values..
https://github.com/vahidhedayati/ajaxdependancyselection/blob/master/grails-app/services/ajaxdependancyselection/AutoCompleteService.groovy
def selectSecondary(params) {
if (params.domain2) {
def domainClass = grailsApplication?.getDomainClass(params?.domain2)?.clazz
def query = {
eq params.bindid, params.id.toLong()
projections {
property(params.collectField)
property(params.searchField)
}
order(params.searchField)
}
def results =domainClass.createCriteria().list(query)
def primarySelectList = []
results.each {
def primaryMap = [:]
primaryMap.put('id', it[0])
primaryMap.put('name', it[1])
primarySelectList.add(primaryMap)
}
return primarySelectList as JSON
}
}
https://github.com/vahidhedayati/ajaxdependancyselection/blob/master/grails-app/taglib/ajaxdependancyselection/AutoCompleteTagLib.groovy
def gsattrs=['optionKey' : "${attrs.collectField}" , 'optionValue': "${attrs.searchField}", 'id': "${attrs.id}", 'value': "${attrs.value}", 'name': "${name}"]
gsattrs['from'] = primarylist
gsattrs['noSelection'] =attrs.noSelection
gsattrs['onchange'] = "${remoteFunction(controller:''+attrs.controller+'', action:''+attrs.action+'', params:'\'id=\' + escape(this.value) +\'&setId='+attrs.setId+'&bindid='+ attrs.bindid+'&collectField='+attrs.collectField2+'&searchField='+attrs.searchField2+'&domain2='+attrs.domain2+'&controller='+attrs.controller+'\'',onSuccess:''+attrs.id+'Update(data)')}"
def link = ['action': attrs.action , 'controller': attrs.controller ]
out<< g.select(gsattrs)
You should be able to use the functionality to reproduce the same effect from a text file if you so wish to go down this route...