sql >> データベース >  >> NoSQL >> MongoDB

マングース-`findOrCreate`を使用して4つを超えるフィールドを作成することはできません

    問題が発生する理由:
    findOrCreateを使用していません よく方法。 findOrCreate 最大4つの引数を取ることができます。
    findOrCreate(conditions, doc, options, callback)

    • conditions :これは、ドキュメントを検索するための選択フィルターを指定するために使用されます。
    • doc [オプション]:selection-filter(conditionsに一致するドキュメントの場合 )が見つかりません、このdoc conditionsにあるものとマージされます その後、DBに挿入されます。
    • options [オプション]:プラグインのコードベースから、options.upsertを使用できると思いました (trueに設定されている場合 )ドキュメントがすでに存在する場合は更新します。
    • callback :操作終了後に実行される機能。

    間違っているのは、passign { email: profile.emails[0].value }です。 optionsの3番目の引数として 予想される場合は、docに含める必要があります つまり、2番目の引数です。

    修正
    これを試してください:

    passport.use(
      new GoogleStrategy(
        {
          clientID: process.env.CLIENT_ID,
          clientSecret: process.env.CLIENT_SECRET,
          callbackURL: "http://localhost:3000/auth/google/dashboard",
          profileFields: ["id", "displayName", "photos", "email"]
        },
        function(accessToken, refreshToken, profile, cb) {
          console.log(profile);
          console.log(profile.photos[0].value);
          User.findOrCreate(
            { googleId: profile.id },
            // Notice that this function parameter below 
            // includes both the profilePic and email
            { profilePic: profile.photos[0].value, email: profile.emails[0].value },
            function(err, user) {
              return cb(err, user);
            }
          );
        }
      )
    );
    



    1. 集約されたMongoDBバージョン3.0を使用してMongoデータを取得する方法

    2. UbuntuのMongodb

    3. Angular、NodeJS、Express、MongoDBを使用してオンラインフードストアWebサイトを作成する

    4. サーバー選択が10000ミリ秒後にタイムアウトしました-ローカルホスト上のmongoDBにCompassを接続できません