在 Mongo shell 中访问我的用户详细信息的命令是什么?

What is the command to access my user details in Mongo shell?

我的 MongoDB 数据库的本地副本中显然有一个用户。

我通过 use server_users 访问了相应的数据库,但是当我这样做 db.getUsers() 时,我得到一个空数组。

但是当我在我的 node REPL 中 运行 时:

> Buffer.from(session, 'base64').toString('utf8')
'{"passport":{"user":"5ad25c401dfbaee22188a93b"}}'

你可以清楚地看到我的 Mongo 数据库中确实有一个用户。

如何在我的 mongo shell 中调出该用户?

这是我的 passport.js 文件:

const passport = require('passport');
const GoogleStrategy = require('passport-google-oauth20').Strategy;
const mongoose = require('mongoose');
const keys = require('../config/keys');

const User = mongoose.model('users');

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

passport.deserializeUser((id, done) => {
  User.findById(id).then(user => {
    done(null, user);
  });
});

// passport.use() is a generic register to make Passport
// aware of new strategy
// creates a new instance to authenticate users
passport.use(
  new GoogleStrategy(
    {
      clientID: keys.googleClientID,
      clientSecret: keys.googleClientSecret,
      callbackURL: '/auth/google/callback',
      proxy: true
    },
    async (accessToken, refreshToken, profile, done) => {
      const existingUser = await User.findOne({ googleId: profile.id });

      if (existingUser) {
        // we already have a record with given profile id
        done(null, existingUser);
      }
      // we dont have a user record with this id, make a new record
      const user = await new User({ googleId: profile.id }).save();
      done(null, user);
    }
  )
);

步骤 1

> show dbs
    admin         0.000GB
    auth          0.000GB
    local         0.000GB
    muber         0.000GB
    seed_data     0.000GB
    server_users  0.000GB
    upstar_music  0.004GB
    users_test    0.000GB

第 2 步

> use auth
switched to db auth

步骤 3

> db.getCollection('users').find({}).pretty()
{
    "_id" : ObjectId("5cedf41999c20922fd05cdce"),
    "email" : "test123@example.com",
    "password" : "a$Yu194aPMrwuA6JZStTwu7OmaAugFNM1XvXDDBVpF1d5wKKHaPmLFe",
    "__v" : 0
}
{
    "_id" : ObjectId("5ceee2237d1b22dfbf37820f"),
    "email" : "test99@example.com",
    "password" : "a$.a9jWOSQbLG32lInCCUwGeqZDM9ksbTN7MDMo1kbOaApmMUr3cCLO",
    "__v" : 0
}
{
    "_id" : ObjectId("5ceeeb02d35e4ee61d602040"),
    "email" : "test919@example.com",
    "password" : "a$fSq31UO/4IEPMaXzgIHXK.zlMO8IUPsVh4Vf9MRo7zldk9dSgiwVS",
    "__v" : 0
}
{
    "_id" : ObjectId("5ceeee0bd72c8ae85dcbbc7f"),
    "email" : "test900@example.com",
    "password" : "a$l/99bU2MpElHhVFNXk1tB.k69DOAcdc/ySuek33MjtjAB0yLTqAqi",
    "__v" : 0
}
{
    "_id" : ObjectId("5ceef1cddf3064eaf8530f68"),
    "email" : "test901@example.com",
    "password" : "a$aKzilNGIm9HZx0iSXhsvbe9UCFqNt5FWjVd7T.GX7uKawAfCyG3JS",
    "__v" : 0
}
{
    "_id" : ObjectId("5cef25fc43a429ec05759849"),
    "email" : "test902@example.com",
    "password" : "a$JY0w/UuvT4Ub7T3RR9.VVOIH6V4RX9bTwoWzwEBbTiidPEiasakNq",
    "__v" : 0
}