balderdashy / sails

Realtime MVC Framework for Node.js
https://sailsjs.com
MIT License
22.83k stars 1.95k forks source link

Error: A model (`user`) references a datastore which cannot be found (`mongodb`). #4433

Closed SpaceG closed 5 years ago

SpaceG commented 6 years ago
error: 
error: Error: A model (`user`) references a datastore which cannot be found (`mongodb`).  If this model definition has an explicit `datastore` property, check that it is spelled correctly.  If not, check your default `datastore` (usually located in `config/models.js`)

anyone a idea?.. my data from the oauth facebook does not save in the mongoDB. ?

what im doing wrong?

my user.js

const bcrypt = require('bcrypt-nodejs');

module.exports = {

  datastore: 'myMongoDb2',

  attributes: {
      email: {
        type: 'string',
        isEmail: true,
      },
    username: {
      type: 'string',
      required: true,
      unique: true
    },
    password: {
      type: 'string',
      required: true
    },
    state: {
      type: 'string',
      isIn: ['pending', 'approved', 'denied'],
      defaultsTo: 'pending'
    },
    provider: {
      type: 'string',
      isIn: ['local', 'github', 'twitter', 'facebook'],
      defaultsTo: 'local'
    },
    uid: {
      type: 'string'
    },
    // One-to-Many -> Add a reference to Posts 

    },
  customToJSON: function() {
     return _.omit(this, ['password'])
  },
  beforeCreate: function(user, cb){
    bcrypt.genSalt(10, function(err, salt){
      bcrypt.hash(user.password, salt, null, function(err, hash){
        if(err) return cb(err);
        user.password = hash;
        return cb();
      });
    });
  }
};

my datastore.js


module.exports.datastores = {

  /***************************************************************************
  *                                                                          *
  * Your app's default datastore.                                            *
  *                                                                          *
  * Sails apps read and write to local disk by default, using a built-in     *
  * database adapter called `sails-disk`.  This feature is purely for        *
  * convenience during development; since `sails-disk` is not designed for   *
  * use in a production environment.                                         *
  *                                                                          *
  * To use a different db _in development_, follow the directions below.     *
  * Otherwise, just leave the default datastore as-is, with no `adapter`.    *
  *                                                                          *
  * (For production configuration, see `config/env/production.js`.)          *
  *                                                                          *
  ***************************************************************************/

  default: {

    /***************************************************************************
    *                                                                          *
    * Want to use a different database during development?                     *
    *                                                                          *
    * 1. Choose an adapter:                                                    *
    *    https://sailsjs.com/plugins/databases                                 *
    *                                                                          *
    * 2. Install it as a dependency of your Sails app.                         *
    *    (For example:  npm install sails-mysql --save)                        *
    *                                                                          *
    * 3. Then pass it in, along with a connection URL.                         *
    *    (See https://sailsjs.com/config/datastores for help.)                 *
    *                                                                          *
    ***************************************************************************/
   adapter: 'sails-mongo',
   url: 'mongodb://localhost:27017/myMongoDb2',

  },

};

my passport.js

const passport = require('passport'),
      LocalStrategy = require('passport-local').Strategy,

      GitHubStrategy = require('passport-github2').Strategy,
      TwitterStrategy = require('passport-twitter').Strategy,
      FacebookStrategy = require('passport-facebook').Strategy,

      shortid = require('shortid');
      generatePassword = require('password-generator');

      bcrypt = require('bcrypt');

      passport.serializeUser(function (user, done) {
        done(null, user.id);
      });

      passport.deserializeUser(function (id, done) {
        User.findOne({id: id}, function (err, user) {
          done(err, user);
        });
      });

      /*

      passport.serializeUser(function(user, done) {
        done(null, user.facebookId);
      });

      passport.deserializeUser(function(user, done) {
        done(null, user);
      });

      */

/*

      passport.serializeUser(function(user, done) {
        done(null, user.id);
    });

    passport.deserializeUser(function(id, done) {
        User.findOneById(id).done(function (err, user) {
            done(err, user);
        });
    });

      */

passport.use(new LocalStrategy({
    usernameField: 'email',
    passwordField: 'password'
  },
  function(email, password, done) {

    User.findOne({ email: email }, function (err, user) {
      if (err) { return done(err); }
      if (!user) {
        return done(null, false, { message: 'Incorrect email.' });
      }

      bcrypt.compare(password, user.password, function (err, res) {
          if (!res)
            return done(null, false, {
              message: 'Invalid Password'
            });
          var returnUser = {
            username: user.username,
            createdAt: user.createdAt,
            id: user.id
          };
          return done(null, returnUser, {
            message: 'Logged In Successfully'
          });
        });
    });
  }
));

/*
passport.use(new FacebookStrategy({
  clientID: '169553873736123',
  clientSecret: '3dfef9e57f803b5879700a27d9ff81c3',
  callbackURL: "http://localhost:1337/auth/facebook/callback",
  profileFields: ['email']
},
  function(accessToken, refreshToken, profile, done) {
    User.findOne({ email: profile.emails[0].value}, function(err, user){
      if (err) { return done(err); }
      if (!user || user == 'false') {
        console.log('No user found');
        console.log(profile.id);
        User.create({facebookId: profile.id, email: profile.emails[0].value}, function(err, user){
          return done(null, user, { message: 'Facebook user created'});
        })
      } else {
        console.log(user);
        return done(null, user, { message: 'User already registered'});
      }
    })
  }
));*/

passport.use(new FacebookStrategy({
  clientID: '169553873736123',
  clientSecret: '3dfef9e57f803b5879700a27d9ff81c3',
  callbackURL: "http://localhost:1337/auth/facebook/callback"
},
function(token, tokenSecret, profile, done) {

  User.findOne({ uuid: profile.id, provider: profile.provider }, function(err, user) {

    if (user) {
      return done(null, user.id);
    } else {

      var data = {
        id: 12345, 
        provider: profile.provider,
        uid: profile.id,
        username: profile.username
      };

      var shortid = require('shortid'),
          generatePassword = require('password-generator');

      //Let's generate a fake email and a fake password to match the User model attributes    
      var fakeEmail = 'fake_' + new Date().getTime() + '_' + shortid.generate() + '@fake.com';
          data.email = fakeEmail;

      var password = generatePassword(12, false); 
          data.password = password;         

          User.create(data, function(err, user) {
            if (err) { return done(err); }
            return done(null, user, {
              message: 'Logged In Successfully'
            });
      });
    }
  });
}
));

my AuthController.js


// oAuth beginning here 

facebook: function(req, res){

  passport.authenticate('facebook')(req,res);

},

facebookCallback: function (req, res, next) {

  passport.authenticate('facebook', {scope: ['email', 'profile.id']}, function (err, user) {
    req.logIn(user, function (err) {
      if(err) {
        res.redirect('/');
      } else {
        res.session.user = user;
        res.redirect('/');
      }
    });
  })(req, res, next);

},

};

Sails version1.0.1: Node versionv8.10.0: NPM version: DB adapter name: N/A DB adapter version: N/A Operating system:

sailsbot commented 6 years ago

Hi @SpaceG! It looks like you may have removed some required elements from the initial comment template, without which I can't verify that this post meets our contribution guidelines. To re-open this issue, please copy the template from here, paste it at the beginning of your initial comment, and follow the instructions in the text. Then post a new comment (e.g. "ok, fixed!") so that I know to go back and check.

Sorry to be a hassle, but following these instructions ensures that we can help you in the best way possible and keep the Sails project running smoothly.

*If you feel this message is in error, or you want to debate the merits of my existence (sniffle), please contact inquiries@sailsjs.com

ptdede commented 6 years ago

@SpaceG Please see documentation Model - datastore section

The name of the datastore configuration that a model will use to find records, create records, etc.

it tell that datastore key inside Model is reference of datastore name inside datastore configuration (./config/datastores.js)

and you don't have datastore named "myMongoDb2", only "default" datastore is there. that's why i think sails log clearly said.

error: Error: A model (user) references a datastore which cannot be found (mongodb). If this model definition has an explicit datastore property, check that it is spelled correctly. If not, check your default datastore (usually located in config/models.js)

you can omit datastore key attribute inside your User Model and try lift your app again. Wish you luck 👍

SpaceG commented 6 years ago

@ptdede thanks. you mean in the config/model.js

my model.js


/**
 * Default model settings
 * (sails.config.models)
 *
 * Your default, project-wide model settings. Can also be overridden on a
 * per-model basis by setting a top-level properties in the model definition.
 *
 * For details about all available model settings, see:
 * https://sailsjs.com/config/models
 *
 * For more general background on Sails model settings, and how to configure
 * them on a project-wide or per-model basis, see:
 * https://sailsjs.com/docs/concepts/models-and-orm/model-settings
 */

module.exports.models = {

  /***************************************************************************
  *                                                                          *
  * Whether the `.create()` and `.update()` model methods should ignore      *
  * (and refuse to persist) unrecognized data-- i.e. properties other than   *
  * those explicitly defined by attributes in the model definition.          *
  *                                                                          *
  * To ease future maintenance of your code base, it is usually a good idea  *
  * to set this to `true`.                                                   *
  *                                                                          *
  * > Note that `schema: false` is not supported by every database.          *
  * > For example, if you are using a SQL database, then relevant models     *
  * > are always effectively `schema: true`.  And if no `schema` setting is  *
  * > provided whatsoever, the behavior is left up to the database adapter.  *
  * >                                                                        *
  * > For more info, see:                                                    *
  * > https://sailsjs.com/docs/concepts/orm/model-settings#?schema           *
  *                                                                          *
  ***************************************************************************/

  // schema: true,

  /***************************************************************************
  *                                                                          *
  * How and whether Sails will attempt to automatically rebuild the          *
  * tables/collections/etc. in your schema.                                  *
  *                                                                          *
  * > Note that, when running in a production environment, this will be      *
  * > automatically set to `migrate: 'safe'`, no matter what you configure   *
  * > here.  This is a failsafe to prevent Sails from accidentally running   *
  * > auto-migrations on your production database.                           *
  * >                                                                        *
  * > For more info, see:                                                    *
  * > https://sailsjs.com/docs/concepts/orm/model-settings#?migrate          *
  *                                                                          *
  ***************************************************************************/

 migrate: 'alter',

  /***************************************************************************
  *                                                                          *
  * Base attributes that are included in all of your models by default.      *
  * By convention, this is your primary key attribute (`id`), as well as two *
  * other timestamp attributes for tracking when records were last created   *
  * or updated.                                                              *
  *                                                                          *
  * > For more info, see:                                                    *
  * > https://sailsjs.com/docs/concepts/orm/model-settings#?attributes       *
  *                                                                          *
  ***************************************************************************/

  attributes: {
    createdAt: { type: 'number', autoCreatedAt: true, },
    updatedAt: { type: 'number', autoUpdatedAt: true, },
    id: { type: 'string', columnName: '_id' },
    //--------------------------------------------------------------------------
    //  /\   Using MongoDB?
    //  ||   Replace `id` above with this instead:
    //
    // ```
    // id: { type: 'string', columnName: '_id' },
    // ```
    //--------------------------------------------------------------------------
  },

  /******************************************************************************
  *                                                                             *
  * The set of DEKs (data encryption keys) for at-rest encryption.              *
  * i.e. when encrypting/decrypting data for attributes with `encrypt: true`.   *
  *                                                                             *
  * > The `default` DEK is used for all new encryptions, but multiple DEKs      *
  * > can be configured to allow for key rotation.  In production, be sure to   *
  * > manage these keys like you would any other sensitive credential.          *
  *                                                                             *
  * > For more info, see:                                                       *
  * > https://sailsjs.com/docs/concepts/orm/model-settings#?dataEncryptionKeys  *
  *                                                                             *
  ******************************************************************************/

  dataEncryptionKeys: {
    default: '531tiQkqOiATGOmKzq9s8uhJCBLUVOFj7zL4w/lGD2k='
  },

  /***************************************************************************
  *                                                                          *
  * Whether or not implicit records for associations should be cleaned up    *
  * automatically using the built-in polyfill.  This is especially useful    *
  * during development with sails-disk.                                      *
  *                                                                          *
  * Depending on which databases you're using, you may want to disable this  *
  * polyfill in your production environment.                                 *
  *                                                                          *
  * (For production configuration, see `config/env/production.js`.)          *
  *                                                                          *
  ***************************************************************************/

  cascadeOnDestroy: true

};

i dont understand what you mean, whit

this is the datastore.js connect to mongodb. - it tell that datastore key inside Model is reference of datastore name inside datastore configuration (./config/datastores.js)

try this shit to fix since 3 days, im now ion angular.js found a solution in 30 mins. - it suck. sorry

sailsbot commented 6 years ago

Hi @SpaceG! It looks like you may have removed some required elements from the initial comment template, without which I can't verify that this post meets our contribution guidelines. To re-open this issue, please copy the template from here, paste it at the beginning of your initial comment, and follow the instructions in the text. Then post a new comment (e.g. "ok, fixed!") so that I know to go back and check.

Sorry to be a hassle, but following these instructions ensures that we can help you in the best way possible and keep the Sails project running smoothly.

*If you feel this message is in error, or you want to debate the merits of my existence (sniffle), please contact inquiries@sailsjs.com

SpaceG commented 6 years ago

info: Starting app...

error: A hook (orm) failed to load! error: error: Error: A model (user) references a datastore which cannot be found (myMongoDb2). If this model definition has an explicit datastore property, check that it is spelled correctly. If not, check your default datastore (usually located in config/models.js

sailsbot commented 6 years ago

Hi @SpaceG! It looks like you may have removed some required elements from the initial comment template, without which I can't verify that this post meets our contribution guidelines. To re-open this issue, please copy the template from here, paste it at the beginning of your initial comment, and follow the instructions in the text. Then post a new comment (e.g. "ok, fixed!") so that I know to go back and check.

Sorry to be a hassle, but following these instructions ensures that we can help you in the best way possible and keep the Sails project running smoothly.

*If you feel this message is in error, or you want to debate the merits of my existence (sniffle), please contact inquiries@sailsjs.com

SpaceG commented 6 years ago

info: Starting app...

error: A hook (orm) failed to load! error: error: Error: A model (user) references a datastore which cannot be found (myMongoDb2). If this model definition has an explicit datastore property, check that it is spelled correctly. If not, check your default datastore (usually located in config/models.js

SpaceG commented 6 years ago

info: Starting app...

error: A hook (orm) failed to load! error: error: Error: A model (user) references a datastore which cannot be found (myMongoDb2). If this model definition has an explicit datastore property, check that it is spelled correctly. If not, check your default datastore (usually located in config/models.js

SpaceG commented 6 years ago

info: Starting app...

error: A hook (orm) failed to load! error: error: Error: A model (user) references a datastore which cannot be found (myMongoDb2). If this model definition has an explicit datastore property, check that it is spelled correctly. If not, check your default datastore (usually located in config/models.js

sailsbot commented 6 years ago

Hi @SpaceG! It looks like you may have removed some required elements from the initial comment template, without which I can't verify that this post meets our contribution guidelines. To re-open this issue, please copy the template from here, paste it at the beginning of your initial comment, and follow the instructions in the text. Then post a new comment (e.g. "ok, fixed!") so that I know to go back and check.

Sorry to be a hassle, but following these instructions ensures that we can help you in the best way possible and keep the Sails project running smoothly.

*If you feel this message is in error, or you want to debate the merits of my existence (sniffle), please contact inquiries@sailsjs.com

SpaceG commented 6 years ago

Fuck off...

sailsbot commented 6 years ago

Hi @SpaceG! It looks like you may have removed some required elements from the initial comment template, without which I can't verify that this post meets our contribution guidelines. To re-open this issue, please copy the template from here, paste it at the beginning of your initial comment, and follow the instructions in the text. Then post a new comment (e.g. "ok, fixed!") so that I know to go back and check.

Sorry to be a hassle, but following these instructions ensures that we can help you in the best way possible and keep the Sails project running smoothly.

*If you feel this message is in error, or you want to debate the merits of my existence (sniffle), please contact inquiries@sailsjs.com

SpaceG commented 6 years ago

my user.js motherfucking file named
datastore: 'myMongoDb2',


const bcrypt = require('bcrypt-nodejs');

module.exports = {

  datastore: 'myMongoDb2',

  attributes: {
      email: {
        type: 'string',
        isEmail: true,
      },
    username: {
      type: 'string',
      required: true,
      unique: true
    },
    password: {
      type: 'string',
      required: true
    },
    state: {
      type: 'string',
      isIn: ['pending', 'approved', 'denied'],
      defaultsTo: 'pending'
    },
    provider: {
      type: 'string',
      isIn: ['local', 'github', 'twitter', 'facebook'],
      defaultsTo: 'local'
    },
    uid: {
      type: 'string'
    },
    // One-to-Many -> Add a reference to Posts 

    },
  customToJSON: function() {
     return _.omit(this, ['password'])
  },
  beforeCreate: function(user, cb){
    bcrypt.genSalt(10, function(err, salt){
      bcrypt.hash(user.password, salt, null, function(err, hash){
        if(err) return cb(err);
        user.password = hash;
        return cb();
      });
    });
  }
};

and my fucking datastroe.js file

my datastore.js

both namede myMongoDb2', ! what the henk are you fucking talk about?


module.exports.datastores = {

  /***************************************************************************
  *                                                                          *
  * Your app's default datastore.                                            *
  *                                                                          *
  * Sails apps read and write to local disk by default, using a built-in     *
  * database adapter called `sails-disk`.  This feature is purely for        *
  * convenience during development; since `sails-disk` is not designed for   *
  * use in a production environment.                                         *
  *                                                                          *
  * To use a different db _in development_, follow the directions below.     *
  * Otherwise, just leave the default datastore as-is, with no `adapter`.    *
  *                                                                          *
  * (For production configuration, see `config/env/production.js`.)          *
  *                                                                          *
  ***************************************************************************/

  default: {

    /***************************************************************************
    *                                                                          *
    * Want to use a different database during development?                     *
    *                                                                          *
    * 1. Choose an adapter:                                                    *
    *    https://sailsjs.com/plugins/databases                                 *
    *                                                                          *
    * 2. Install it as a dependency of your Sails app.                         *
    *    (For example:  npm install sails-mysql --save)                        *
    *                                                                          *
    * 3. Then pass it in, along with a connection URL.                         *
    *    (See https://sailsjs.com/config/datastores for help.)                 *
    *                                                                          *
    ***************************************************************************/
   adapter: 'sails-mongo',
   url: 'mongodb://localhost:27017/myMongoDb2',

  },

};
SpaceG commented 6 years ago

MANNNNN!!!!!!! i cant believe it really! i give up with sailsJS GameOver!!!!!!!!!

error: error: { Error: Invalid configuration for datastore myMongoDb2: No url was specified, and no appropriate connection URL can be inferred (tried to use host: undefined).

Please specify a host... Or better yet, specify a url! (See http://sailsjs.com/config/datastores#?the-connection-url for more info.)

SpaceG commented 6 years ago
/**
 * Datastores
 * (sails.config.datastores)
 *
 * A set of datastore configurations which tell Sails where to fetch or save
 * data when you execute built-in model methods like `.find()` and `.create()`.
 *
 *  > This file is mainly useful for configuring your development database,
 *  > as well as any additional one-off databases used by individual models.
 *  > Ready to go live?  Head towards `config/env/production.js`.
 *
 * For more information on configuring datastores, check out:
 * https://sailsjs.com/config/datastores
 */

module.exports.datastores = {

  /***************************************************************************
  *                                                                          *
  * Your app's default datastore.                                            *
  *                                                                          *
  * Sails apps read and write to local disk by default, using a built-in     *
  * database adapter called `sails-disk`.  This feature is purely for        *
  * convenience during development; since `sails-disk` is not designed for   *
  * use in a production environment.                                         *
  *                                                                          *
  * To use a different db _in development_, follow the directions below.     *
  * Otherwise, just leave the default datastore as-is, with no `adapter`.    *
  *                                                                          *
  * (For production configuration, see `config/env/production.js`.)          *
  *                                                                          *
  ***************************************************************************/

 myMongoDb2: {

    /***************************************************************************
    *                                                                          *
    * Want to use a different database during development?                     *
    *                                                                          *
    * 1. Choose an adapter:                                                    *
    *    https://sailsjs.com/plugins/databases                                 *
    *                                                                          *
    * 2. Install it as a dependency of your Sails app.                         *
    *    (For example:  npm install sails-mysql --save)                        *
    *                                                                          *
    * 3. Then pass it in, along with a connection URL.                         *
    *    (See https://sailsjs.com/config/datastores for help.)                 *
    *                                                                          *
    ***************************************************************************/
   adapter: 'sails-mongo',
   //url: 'mongodb://localhost:27017/myMongoDb2',

  },

};
sailsbot commented 6 years ago

Hi @SpaceG! It looks like you may have removed some required elements from the initial comment template, without which I can't verify that this post meets our contribution guidelines. To re-open this issue, please copy the template from here, paste it at the beginning of your initial comment, and follow the instructions in the text. Then post a new comment (e.g. "ok, fixed!") so that I know to go back and check.

Sorry to be a hassle, but following these instructions ensures that we can help you in the best way possible and keep the Sails project running smoothly.

*If you feel this message is in error, or you want to debate the merits of my existence (sniffle), please contact inquiries@sailsjs.com

SpaceG commented 6 years ago

what the henk.? there give me out this error !

sailsbot commented 6 years ago

Hi @SpaceG! It looks like you may have removed some required elements from the initial comment template, without which I can't verify that this post meets our contribution guidelines. To re-open this issue, please copy the template from here, paste it at the beginning of your initial comment, and follow the instructions in the text. Then post a new comment (e.g. "ok, fixed!") so that I know to go back and check.

Sorry to be a hassle, but following these instructions ensures that we can help you in the best way possible and keep the Sails project running smoothly.

*If you feel this message is in error, or you want to debate the merits of my existence (sniffle), please contact inquiries@sailsjs.com

SpaceG commented 6 years ago

rror: error: { Error: Invalid configuration for datastore myMongoDb2: No url was specified, and no appropriate connection URL can be inferred (tried to use host: undefined).

Please specify a host... Or better yet, specify a url! (See http://sailsjs.com/config/datastores#?the-connection-url for more info.) at Object.registerDatastore (/Users/jh/Desktop/new/oauthy Kopie/node_modules/sails-mongo/lib/index.js:209:58) at /Users/jh/Desktop/new/oauthy Kopie/node_modules/waterline/lib/waterline.js:714:27 at /Users/jh/Desktop/new/oauthy Kopie/node_modules/async/dist/async.js:3047:20 at eachOfArrayLike (/Users/jh/Desktop/new/oauthy Kopie/node_modules/async/dist/async.js:1002:13) at eachOf (/User

SpaceG commented 6 years ago

info: ·• Auto-migrating... (alter) info: Hold tight, this could take a moment. error: A hook (orm) failed to load! error: error: Error: In model user, primary key id must have either required or autoIncrement set. at /Users/jh/Desktop/new/oauthy Kopie/node_modules/sails-disk/index.js:120:25 at /Users/jh/Desktop/new/oauthy Kopie/node_modules/async/dist/async.js:3047:20 at eachOfArrayLike (/Users/jh/Desktop/new/oauthy Kopie/node_modules/async/dist/async.js:1002:13) at eachOf (/Users/jh/Desktop/new/oauthy Kopie/node_modules/async/dist/async.js:1052:9)

SpaceG commented 6 years ago
 info: ·• Auto-migrating...  (alter)
 info:    Hold tight, this could take a moment.
error: A hook (`orm`) failed to load!
error: 
error: Error: In model `user`, primary key `id` must have either `required` or `autoIncrement` set.
    at /Users/jh/Desktop/new/oauthy Kopie/node_modules/sails-disk/index.js:120:25
    at /Users/jh/Desktop/new/oauthy Kopie/node_modules/async/dist/async.js:3047:20
    at eachOfArrayLike (/Users/jh/Desktop/new/oauthy Kopie/node_modules/async/dist/async.js:1002:13)
    at eachOf (/Users/jh/Desktop/new/oauthy Kopie/node_modules/async/dist/async.js:1052:9)
SpaceG commented 6 years ago

@ptdede

ptdede commented 6 years ago

@SpaceG Please read carefully the instruction. I knew you're getting frustration but you have to clear your mind first before posting this issue.

this error Error: A model (user) references a datastore which cannot be found (mongodb). i think happens because you set datastore attribute inside your user.js model.

const bcrypt = require('bcrypt-nodejs');

module.exports = {

  // THIS ONE vvvvvvvvvvvvvvvv
  **datastore: 'mongodb',**
  // THIS ONE ^^^^^^^^^^^^^^^^^^^

  attributes: {
      email: {
        type: 'string',
        isEmail: true,
      },
    username: {
      type: 'string',
      required: true,
      unique: true
    },
    password: {
      type: 'string',
      required: true
    },
    state: {
      type: 'string',
      isIn: ['pending', 'approved', 'denied'],
      defaultsTo: 'pending'
    },
    provider: {
      type: 'string',
      isIn: ['local', 'github', 'twitter', 'facebook'],
      defaultsTo: 'local'
    },
    uid: {
      type: 'string'
    },
    // One-to-Many -> Add a reference to Posts 

    },
  customToJSON: function() {
     return _.omit(this, ['password'])
  },
  beforeCreate: function(user, cb){
    bcrypt.genSalt(10, function(err, salt){
      bcrypt.hash(user.password, salt, null, function(err, hash){
        if(err) return cb(err);
        user.password = hash;
        return cb();
      });
    });
  }
};

tell me what happen after you remove that line? What is your native language in your country?

ptdede commented 6 years ago

@SpaceG Wow. another issues appear? hahahaha..

/**
 * Datastores
 * (sails.config.datastores)
 *
 * A set of datastore configurations which tell Sails where to fetch or save
 * data when you execute built-in model methods like `.find()` and `.create()`.
 *
 *  > This file is mainly useful for configuring your development database,
 *  > as well as any additional one-off databases used by individual models.
 *  > Ready to go live?  Head towards `config/env/production.js`.
 *
 * For more information on configuring datastores, check out:
 * https://sailsjs.com/config/datastores
 */

module.exports.datastores = {

  /***************************************************************************
  *                                                                          *
  * Your app's default datastore.                                            *
  *                                                                          *
  * Sails apps read and write to local disk by default, using a built-in     *
  * database adapter called `sails-disk`.  This feature is purely for        *
  * convenience during development; since `sails-disk` is not designed for   *
  * use in a production environment.                                         *
  *                                                                          *
  * To use a different db _in development_, follow the directions below.     *
  * Otherwise, just leave the default datastore as-is, with no `adapter`.    *
  *                                                                          *
  * (For production configuration, see `config/env/production.js`.)          *
  *                                                                          *
  ***************************************************************************/

 // why you did this? why not set it to default and remove datastore attribute inside your user.js ?
 myMongoDb2: {

    /***************************************************************************
    *                                                                          *
    * Want to use a different database during development?                     *
    *                                                                          *
    * 1. Choose an adapter:                                                    *
    *    https://sailsjs.com/plugins/databases                                 *
    *                                                                          *
    * 2. Install it as a dependency of your Sails app.                         *
    *    (For example:  npm install sails-mysql --save)                        *
    *                                                                          *
    * 3. Then pass it in, along with a connection URL.                         *
    *    (See https://sailsjs.com/config/datastores for help.)                 *
    *                                                                          *
    ***************************************************************************/
   adapter: 'sails-mongo',
   //url: 'mongodb://localhost:27017/myMongoDb2',

  },

};

Do you want to have multiple databases for storing data or you're only using mongo? if only mongo, change "myMongoDb2" back to "default", and remove datastore: 'myMongoDb2' in user.js

And my suggestion is find a good tutorial for sails.js (basic) to understand the flow of the app and how to handling error better in the future. 👍

NachtRitter commented 6 years ago

@SpaceG just read documentation. All problems in your issues caused by unread documentation. If you don't understand documentation and can't analyze simple errors with full problem description, maybe programming isn't your life way.

luislobo commented 6 years ago

@SpaceG

In your model user.js, if you set the datastore attribute, you have to have a key that matches that name in /config/datastores.js

So, if your model has:

coodule.exports = {
  datastore: 'myMongoDb2',
  attributes: {
      email: {
        type: 'string',
        isEmail: true,
      },

in config/datastores.js you HAVE to have a key named myMongoDb2.

module.exports.datastores = {
 myMongoDb2: {
   // etc
 }
}

Notice the name of the key, it is NOT default, it's myMongoDb2.

The issue that @sailsbot is telling you has to do with how you are supposted to report an Issue. When you report an issue, the issue has a template that is autofilled for you, with this content: https://github.com/balderdashy/sails/blob/master/.github/ISSUE_TEMPLATE

If you modify the text without following instructions in there, then @sailsbot will say report all those errors.

Next time, read and follow the instructions in the Issue template when you create it and you will not have all those messages back from @sailsbot

raqem commented 5 years ago

Hi @ptdede, @NachtRitter, @luislobo thank you all for your advice! @SpaceG I hope you were able to resolve the problem with the help from your fellow Sails users. In an effort to tidy-up the issues for this new year I am going to close this issue. @SpaceG please feel free to create another issue if the need arises.