0

I am trying to set multiple fields with an update in MongoDB using Java

    DBObject nameQuery = new BasicDBObject();
    nameQuery.put(DBUser.LAST_SEEN_NAME_FIELD, player.getName());
    nameQuery.put(DBUser.LAST_SEEN_NAME_LOWER_FIELD, player.getName().toLowerCase());
    nameQuery.put(DBUser.UUID_FIELD, new BasicDBObject("$ne", Database.makeStorableUUID(player.getUniqueId())));

    DBObject updateFields = new BasicDBObject();
    updateFields.put(DBUser.LAST_SEEN_NAME_FIELD, "");
    updateFields.put(DBUser.LAST_SEEN_NAME_LOWER_FIELD, "");

    DBObject nameUpdate = new BasicDBObject("$set", updateFields);

    this.update(nameQuery, nameUpdate);

When this runs it doesn't throw any errors but I would assume there is something wrong with my query or update. I'm hoping someone can point me in the right direction.

PHPDEV
  • 383
  • 1
  • 4
  • 12

1 Answers1

0

I fixed the problem by using updateMulti instead of update.

PHPDEV
  • 383
  • 1
  • 4
  • 12