简体   繁体   English

Nodejs和Angular。 发布后对mongodb db进行更改

[英]Nodejs and Angular. Make changes to mongodb db after posting

I have a nodejs app with Angular for the front-end stuff. 我有一个用于Angular的nodejs应用程序。 I make a post call from the client side that saves a large JSON string in a collection in mongodb. 我从客户端发出了一个帖子,该帖子将一个较大的JSON字符串保存在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: 这是发布大JSON字符串的代码:

           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. 我是nodejs的新手,不确定服务器端代码的工作方式。 Is it handled in the server.js file? 是否在server.js文件中处理? 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. 您有大量的JSON数据,首先要将其存储在集合1中,然后要对其执行一些操作,然后将新的精炼数据保存在其他集合2中。

I am going to give my answer based upon that. 我将据此给出我的答案。

To use Mongo we have various modules available for node js. 要使用Mongo,我们为节点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. 使用各自的模块在mongodb的每个插入条目之后,您将获得一个回调,其中插入了数据。 You can manipulate it and then make one more save operation in another collection. 您可以对其进行操作,然后在另一个集合中再进行一次保存操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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