sql >> Base de Datos >  >> NoSQL >> MongoDB

Error de bucle invertido:se requiere autorización

Ver su último pregunta Me imagino lo que pasó.

De alguna manera la colección Role se creó pero no se asignó a User .

Te sugiero que cambies:

Role.find({ name: 'admin' }, function(err, results) {
            if (err) { throw err; }

            if (results.length < 1) {
                // now we know the DB doesn't have it already, so do the Role creation...
                //create the admin role
                Role.create({
                  name: 'admin'
                }, function(err, role) {
                  if (err) throw (err);
                   //make admin
                  role.principals.create({
                    principalType: RoleMapping.USER,
                    principalId: users[0].id
                  }, function(err, principal) {
                    if (err) throw (err);
                  });
                });
            }
        });

Por:

Role.create({
      name: 'admin'
    }, function(err, role) {
      if (err) throw (err);
       //make admin
      role.principals.create({
        principalType: RoleMapping.USER,
        principalId: users[0].id
      }, function(err, principal) {
        if (err) throw (err);
      });
    });

Suelte la colección de roles:db.Role.drop() y ejecute Loopback de nuevo.

Nota:Estaba haciendo la misma tarea y trabajé para mí.