简体   繁体   中英

Nodejs and Angular. Make changes to mongodb db after posting

I have a nodejs app with Angular for the front-end stuff. I make a post call from the client side that saves a large JSON string in a collection in mongodb. I want the server side to then chop up the data and save it in the desired format in another collection. I cannot post correctly formatted data directly from the browser because that would mean making too many async post calls from the client side. Here is the code to post that big JSON string:

           var request = $http({
                method: "post",
                url: "/students",
                data: {
                    studentData: jsonData
                }
            }).then(function successCallback(response) {
            }, function errorCallback(response) {
                console.log(response);
            });

I am not sure how to proceed from here. I am new to nodejs and am not sure how the server side code works. Is it handled in the server.js file? If so, is it feasible to do what I have described above?

This is what I understood after reading the whole thing. You have a big chunk of JSON data firstly you want to store it in collection 1 and then you want to perform some operation on it and then save the new refined data in some other collection 2.

I am going to give my answer based upon that.

To use Mongo we have various modules available for node js. Let's take mongoose as an example here, although you can use any because the concept remains the same as it is very simple.

After every insert entry to the mongodb using respective module you'll have a callback with data inserted. You can manipulate it and then make one more save operation in another collection.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM