更改Mongodb参数值

时间:2019-03-22 15:18:04

标签: jquery node.js ajax ejs

我想为我网站上的帖子创建一个报告按钮,在我的帖子模型中,我有:报告:,默认值为false,我希望如果有人单击该按钮,该值将更改为true。

我在html页面上的ejs:

<% posts.forEach(function(post){ %>
        <% if(post.uploadedBy == Tuser){ %>
            <div class="jumbotron jumbotron-fluid">
                <div class="container">
                    <h4 class="display-4" style="text-transform: capitalize;"><%= post.title %></h4>
                    <h5><%= post.uploadedBy %></h5>
                    <p class="lead"><%= post.text %></p>
                    <a href="#" onclick="reported(<%= post %>)">Report Post</a>
                </div>
            </div>
        <% } %>
    <% }) %>

app.js文件中页面的我GET:

//get someone else's blog
router.get('/othersblog/:username',(req,res) => {
    Post.find({},(err,posts) => {
        if(err){
            console.log(err);
        }else{           
            res.render('othersblog',{
                headline: "Website | User Blog",
                title: "Blog",
                Tuser: req.params.username,
                posts: posts,
            });
        }
    })
});

如果您知道该怎么做,请帮助我。谢谢。

1 个答案:

答案 0 :(得分:1)

您要做的是为每个map $http_upgrade $connection_upgrade { default upgrade; '' close; } upstream websocket { server 127.0.0.1:4200; server 127.0.0.1:4300; server 127.0.0.1:5656; } server { listen 8002; server_name localhost; location ~ ^\/api(.*) { proxy_pass http://127.0.0.1:8000$1$is_args$args; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } location ~ ^/sockjs-node/ { proxy_pass http://127.0.0.1:4200; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_http_version 1.1; proxy_cache_bypass $http_upgrade; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } location ~ ^/collector/sockjs-node/ { proxy_pass http://127.0.0.1:4300; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_http_version 1.1; proxy_cache_bypass $http_upgrade; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } location ~ ^/collector(.*) { proxy_pass http://127.0.0.1:4300$1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_http_version 1.1; proxy_cache_bypass $http_upgrade; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } location ^~ /push/ { proxy_pass http://127.0.0.1:5656; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_http_version 1.1; proxy_cache_bypass $http_upgrade; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } location ~ { proxy_pass http://127.0.0.1:4200$1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_http_version 1.1; proxy_cache_bypass $http_upgrade; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } } 创建一条获取路线。
在您的post循环中使用此链接

forEach

这是您的路线。

<a href="/posts/report/<%= post._id %>" >Report Post</a>