简体   繁体   English

如何使用节点js更新mongo db中的记录

[英]How to update a record in mongo db using node js

I have created a simple signup and login using node js and mongoDb.我使用 node js 和 mongoDb 创建了一个简单的注册和登录。 I can successfully do signup and login and now I want to add some more data to the user model after logging in from the secret page.我可以成功进行注册和登录,现在我想在从秘密页面登录后向用户模型添加更多数据。 How can I do that?我怎样才能做到这一点?

This is my user model and I want to add some text to user.text field after loggin in:这是我的用户模型,我想在user.text后向user.text字段添加一些文本:

    var mongoose = require("mongoose");

    var UserSchema = mongoose.Schema({
        username: String, 
        password: String,
        text:String
        
    });

    module.exports = mongoose.model("User", UserSchema);

This is my view page (ie, the secret page)这是我的查看页面(即秘密页面)

<h1>Hi, <%= user.username %></h1>
<form action="/birthday" method="post">
<input type="text" name="text">
<button type="submit">Update database</button>
</form>

The text should be shown here after updating .更新后应在此处显示文本

Thanks!谢谢!

You need to make an API on the node process to send the data to.您需要在节点进程上制作 API 以将数据发送到。 I suggest you take a look at stuff like Express.js and google about REST API:s.我建议你看一下 Express.js 和 google 之类的关于 REST API:s 的东西。

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

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