尚未设置findOrCreate方法

问题描述 投票:0回答:2

我已经创建了具有基本用户的自定义用户,并且我正在搜索以下电子邮件是否存在于db中,如果存在电子邮件,则不创建它并记录访问令牌。

module.exports = function (User) {
  let app = require('../../server/server');
  var loopback = require('loopback');

  var credentials = { email: '[email protected]', password: 'password' };
    var filter = {
        'where': {
            'email': credentials.email
        }
    };
    loopback.User.findOrCreate(filter, credentials, function (err) {
        if (err) throw err;

            User.login(credentials, function (err, token) {
                if (err) throw err;
                console.log(token);
                process.exit();
            });

    });

Error:

Error: Cannot call User.findOrCreate(). The findOrCreate method has not been setup. The PersistedModel has not been correctly attached to a DataSource!
node.js loopbackjs
2个回答
0
投票

尝试检查数据源配置,看它是否正确连接到数据库。


0
投票

试试吧

User.findOrCreate(filter, credentials, function (err) { });

与在Loopback doc中一样

PersistedModel.findOrCreate([filter], data, callback)

参考链接:https://apidocs.strongloop.com/loopback/#persistedmodel-findorcreate

© www.soinside.com 2019 - 2024. All rights reserved.