Trying to loop on all updated field I've got and update them dynamically before saving.
Product.findOne({ _id: productNewData['_id'] }, function (err, doc) {
for (var key in productNewData) {
# what do I do here?
}
doc.save();
});
I know that ruby has a send method like this:
doc.send(key) = productNewData[key]
I guess I can validate the params given and use eval
. Is there any other way?
JavaScript and Ruby are object-oriented, dynamic and general-purpose scripting language, which is interpreted rather than compile during runtime. JavaScript can be used as front-end and back-end language using the same language, whereas Ruby is used as a back-end programming language.
Ruby applications are difficult to debug as it has multiple layers of abstraction due to which it will take more time to fix errors, whereas JavaScript applications are easy to debug compared to Ruby. JavaScript can be used for Full stack development due to its node.JS framework, whereas Ruby can’t be used as a Full Stack.
Many companies use JavaScript; some of them are Instagram, eBay, Codecademy, Firebase, Groove shark, Square, sentry etc. Whereas many companies use Ruby, some of them are Intuit, Rap Genius, Instacart, Task Rabbit, Fab, Scribd etc.
Ruby is better for high CPU intensive application development, which involves graphics, image processing etc., whereas Node.JS is not suitable for high CPU application development. JavaScript can be integrated with many applications such as Auth0, Parcel, Yarn, Buttercup, cell and Apache Open whisk etc.
They are two way to acces properties in Javascript: Using dot notation or brackets. Example:
var foo = {bar: 42}
foo.bar // 42
foo["bar"] // 42
var v = "bar"
foo[v] // 42
foo.v // undefined
So:
Product.findOne({ _id: productNewData['_id'] }, function (err, doc) {
for (var key in productNewData) {
doc[key] = productNewData[key]
}
doc.save();
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With