【问题标题】:Mongoose - Save function does nothingMongoose - 保存功能什么都不做
【发布时间】:2017-10-05 17:44:03
【问题描述】:

我正在学习 Mongoose,但在保存用户时遇到了错误。这是我的User Model

这是我的route

MongoDB 连接正确,我在控制台看到了,Postman 只显示了一个Loading Page..

我不知道为什么它不起作用。

提前致谢!

【问题讨论】:

  • 请将您的代码发布为代码块,而不是图像。

标签: node.js mongodb mongoose mean-stack


【解决方案1】:

我解决了。

我的 MongoDB 连接网址是:

mongodb://localhost:27017/alexcaron

我刚刚更新到

mongodb://localhost/alexcaron

【讨论】:

    【解决方案2】:

    根据您的解释,在没有更多日志数据的情况下,使用 Mongoose 4.4.12,可能会使用 new 这个词?

    https://github.com/Automattic/mongoose/blob/master/examples/schema/schema.js#L14

    var mongoose = require('mongoose'),
        User = require('./models/users_model');
    

    对于使用用户:

    var user = new User({
        courriel: "test1",
        password: "test2"
    });
    

    【讨论】:

    • 问题:我的收藏需要创建吗?
    • Mongoose 在保存该模型的第一个文档之前不会创建用户集合。 User.create({"password": "test2", "courriel": "test1"}, function(err, doc) { // User 集合被创建 });
    • 好的,谢谢。我不知道如何获得更多的日志数据,抱歉。
    • 永远不会触发 .save()。
    • 啊!我发现猫鼬无法打开连接。
    猜你喜欢
    • 1970-01-01
    • 2021-05-17
    • 2020-06-08
    • 2018-08-19
    • 1970-01-01
    • 1970-01-01
    • 2018-12-17
    • 2020-01-16
    • 1970-01-01
    相关资源
    最近更新 更多