Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-241

Can't change field data type when using $set

    • Type: Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 0.9.9
    • Component/s: None
    • None

      The following code fails to convert the data type from a boolean to a double (calling $set). If this feature is not supported by $set, perhaps the driver should check the data type and throw an illegal argument exception if the types do not match.

      if (doc.containsField(SiteDocField.HAS_SYND_FEED.key)) {
      final Object obj = doc.get(SiteDocField.HAS_SYND_FEED.key);
      if (obj != null)

      { double value = convertToDouble(obj); pCol.update(new BasicDBObject(SiteDocField.ID.key, id), new BasicDBObject("$set", new BasicDBObject(SiteDocField.HAS_SYND_FEED.key, value)), false, false); }

      else

      { doc.removeField(SiteDocField.HAS_SYND_FEED.key); pCol.save(doc); }

      pDb.getDb().getLastError();
      }

      The code below successfully changes the data type (by calling save(doc)).

      if (doc.containsField(SiteDocField.HAS_SYND_FEED.key)) {
      final Object obj = doc.get(SiteDocField.HAS_SYND_FEED.key);
      if (obj != null)

      { double value = convertToDouble(obj); // THIS IS THE CODE THAT WORKS doc.put(SiteDocField.HAS_SYND_FEED.key, value); pCol.save(doc); }

      else

      { doc.removeField(SiteDocField.HAS_SYND_FEED.key); }

      pCol.save(doc);
      pDb.getDb().getLastError();
      }

            Assignee:
            eliot Eliot Horowitz (Inactive)
            Reporter:
            rn@deftlabs.com Ryan Nitz
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: