Is there a way to only update attributes that have not previously been set:MongoDB

Is there a way to only update attributes that have not previously been set:MongoDB
0
#1

Hi. Im working on MongoDB, I am using a passport and nodejs, with express. I would like the user to be able to modify the user’s own profile. However, with findAndModify, it will overwrite whatever was in the profile, with the profile downloaded from the strategy. Is there an option or something built in that allows me to do this?

passport.use(new GoogleStrategy({
    returnURL: 'http://localhost:3000/auth/google/return',
    realm: 'http://localhost:3000/'
  },
  function(identifier, profile, done) {
    accounts.findAndModify({ openID: identifier },{},
      { openID:identifier, profile:profile}, 
      {update:true, upsert:true, new:true}, function (err, user) {
      return done(err, user);
    });
  }
));
#2

If the user schema is correctly defined then you wouldn’t need to findAndModify within the strategy at all, since a user has to be authenticated to modify their profile, you could just verify authentication as you would any other time and then carry out normal CRUD operations on part of the schema that is not used by the strategy, but again, it depends on how you defined your user schema to correctly target that part.