A
A
ArthurHlushko2020-02-23 12:32:09
MongoDB
ArthurHlushko, 2020-02-23 12:32:09

How to update data in mongodb via angular 8?

There is a UserService where all the data is stored. It is necessary to push certain data to the database when you click on the button.
For example, add different id to data.friends.
How can this be done? I've been sitting on this for hours and still can't figure it out.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
H
hzzzzl, 2020-02-23
@hzzzzl

I don't know the specifics of angular, but I looked here
https://jasonwatmore.com/post/2018/10/29/angular-7...

add different id to data.friends

make a route on the backend like /api/add_friends, where to POST with an array of new ids in the body?
well there already
User.updateOne(
  { _id: user_id }, 
  { $addToSet:    // или $push?
    { friends:  
      $each: newFriendsIdArray    // как-то так, чтобы каждый элемент массива добавился отдельно
    } 
  }
)

A
Anton Shvets, 2020-02-23
@Xuxicheta

No way. Angular is a frontend framework that runs in a browser, mongo is a database and all js libraries for it work on the backend, i.e. on node.js.
Send data from the browser with an http request to the backend, and already in it to the database.
From the front, you can only work with the database with firebase.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question