Firestore update nested data [duplicate] - javascript

This question already has answers here:
How can I update an object inside of an array in firestore?
(1 answer)
How to update an "array of objects" with Firestore?
(18 answers)
Is there any way to update a specific index from the array in Firestore
(3 answers)
Closed 8 months ago.
i am stuck with a problem with firebase (with Vue). I want to add the user id to a specific map (yes, maybe or no) when the user presses a specific button. But Im having trouble add/update the data because its nested.
Here is my data structure in Firestore
I want to add the user id in a map, something like this:
dates: {
[
0: {
yes: [userId1, userId2]
}
]
}
Does anyone can help me pushing the user ids into the arrays?

Unfortunately, right now it is not possible to update a specific element of the array. You can add new items or remove them - look here. But I would consider a little change in the approach and create a collection called dates in which you can define documents, which will contain yes, no, maybe arrays, which can be easily updated - in the way mentioned before.

Related

why is [[],[],[]] different than new Array(3).fill([])? [duplicate]

This question already has an answer here:
If we create an array of objects using new Array(len).fil({}); and then add a key in any of the objects, it gets reflected in all the 3 objects
(1 answer)
Closed 4 years ago.
So my question is the same as in the title. I saw that someone initiated a similar thing here (If we create an array of objects using new Array(len).fil({}); and then add a key in any of the objects, it gets reflected in all the 3 objects) but while everyone accused the improper method of questioning nobody gave a clear answer.
Array(3).fill([]) creates 3 elements referencing the passed object.
The answer is clear in javascript documentation:
The fill() method fills all the elements of an array from a start
index to an end index with a static value
It seems to me like the only answer in the question you linked to is perfectly clear.
Array.fill "fills" the array with static values. That is to say, you are creating on single empty array and then referencing it in all three of the locations, hence it is the same array in each of the outer array's indices

React Redux Array Filter [duplicate]

This question already has an answer here:
React Redux Cant add item into list in the state
(1 answer)
Closed 4 years ago.
Could some one tell how this image data iterate using array map and assign into the UL LI tag
Assume this is the response generated from and I want to populate this data somewhere.
Specify key to access payload.
return { ...state, filterArr : filterArr }

Retrieving parameter from query string based on another string in Javascript [duplicate]

This question already has answers here:
Accessing an object property with a dynamically-computed name
(19 answers)
Closed 4 years ago.
My app in Google Apps Script gets data from a form that I want to process.
The element form is received and contains the different parameters and values.
If I log the element form it looks like {uid=11, tradingname=xxx, email=yyy}
I can pick up the separate values by running form.uid or form.tradingname for example. But what I want is to pick up the parameters from the element form by referring to a String "uid" (because I get this value form the headers row of the spreadsheet).
Is there a simple way I can do this in one line, for example something like:
form.element["uid"]
So far I've only found difficult methods like https://gomakethings.com/how-to-get-the-value-of-a-querystring-with-native-javascript/ and I would think that I should be able to do this in an easier way.
Thanks!
You can use $("#yourform").serializeArray() and then iterate to match "name" values you want

How do you update values in mongo db object with a function? [duplicate]

This question already has answers here:
Update MongoDB field using value of another field
(12 answers)
Closed 5 years ago.
I'm using mongo db with mongoose and node.js making a web app. I want to update the "stocks" value of all entries of the mongo db using a function. The mongo methods allow you to do specific functions, such as multiplying or adding, but I want a unique function. For example, Topic is the mongoose object, and a common mongo method looks like:
Topic.update(
{ _id: 1 },
{ $inc: { stock: 5 },
{ multi: true }
)
This says to update all entries with _id: 1 by adding 5 to every "stock". What if I want to use a function like (stock * a)+b, where a is a variable defined before the Topic.update method and b is another category in the Topic mongo db.
One way might be to use Topic.find({}) and save to an array, then iterate through it with javascript array methods, then save this as the mongo Topic. But isn't there a way to do this with mongo simpler? A built in method?
A broader question is what are stardard mongoose/mongo/javascript practices and workflow for updating dbs, and more importantly, where do I find them!
The mongo methods allow you to do specific functions, such as multiplying or adding, but I want a unique function.
Nope, if you want to be fast, you're limited to the built-in operators. No custom functions for you. And no referencing other fields/documents.
(which is a pity, really. The need to reference other fields in the document is so natural, one would think...)

Firebase orderBy descending [duplicate]

This question already has answers here:
Display posts in descending posted order
(19 answers)
Closed 5 years ago.
I have an array in Firebase, which I'm getting like this:
var ref = new Firebase(url);
ref.orderByChild("date").on("child_added", function(obj) {
console.log(obj.val());
});
But I need that in descending order. How can I do that with Firebase?
Thanks!
Since you added the AngularJS tag, I'll assume you're using Angular in your project. In that case, it would make your life significantly easier to use AngularFire (http://angularfire.com).
Once you're using AngularFire, you can use the $firebaseArray service to grab your array from your database, and sort it just as you would any other array.
The $firebaseArray documentation can be found here: https://www.firebase.com/docs/web/libraries/angular/guide/synchronized-arrays.html

Categories

Resources