猫鼬不保存多行字符串

时间:2020-07-15 16:05:23

标签: node.js mongodb mongoose

当我尝试将多行字符串放入猫鼬数据库时,它不起作用。它只保存字符串的一行。

将内容记录到控制台:

Console output of string

网站结果:

enter image description here

EJS代码

            <div class="btn-simular">
              <button class="btn">
                Quero Contratar
              </button>
            </div>

猫鼬模型:

<% posts.forEach(function(post){ %>
    <div class="card mb-2" style="width: 100%;">
        <div class="card-body">
          <% if(user.admin == true || user.id == post.authorid){ %>
            <form action="/deletepost/<%= post.id %>" method="post">
              <button type="submit" class="btn btn-sm btn-danger btn-block">Delete</button>
            </form>
            <br>
          <% } %>
          <h5 class="card-title"><a href="http://mywebsite/profile/<%= post.authorid %>"><%= post.authorname %></a></h5>
          <h6 class="card-subtitle mb-2 text-muted"><%= post.date %></h6>
          <hr>
          <p class="card-text"><%= post.content %></p>
        </div>
    </div>
<% }); %>

我如何保存到数据库:

const PostSchema = new mongoose.Schema({
  content: {
    type: String
  }
})

如果需要的话,我会使用express&ejs。

0 个答案:

没有答案