Quantcast
Channel: Spring Community Forums - NoSQL
Viewing all articles
Browse latest Browse all 128

2 bugs for spring data mongodb

$
0
0
1. for CompoundIndex, if name is not set, it will raise an exception: com.mongodb.MongoException: no index name specified. Because in org.springframework.data.mongodb.core.index.MongoP ersistentEntityIndexCreator.checkForIndexes(MongoP ersistentEntity<?> entity)

Code:

String name = index.name();
  if (!StringUtils.hasText(name)) {
    name = persistentProperty.getFieldName();
  }

persistentProperty.getFieldName() cannot correctly get a field name for a compound index, name will be null

and then in DBCollection.ensureIndex

Code:

 
DBObject opts = new BasicDBObject();
  opts.put("name", name);
  opts.put("dropDups", dropDups);
  opts.put("sparse", sparse);
  opts.put("unique", unique);

here also does not check the name value, and then finally name was set to null.

2. in org.springframework.data.mongodb.core.convert.Quer yMapper.Keyword.isKeyword(Object value),
Code:

  if (value instanceof String) {
  return ((String) value).startsWith("$");
  }

here simply check whether a String value is a key world, just with an "$" symbol.

and in org.springframework.data.mongodb.core.convert.Quer yMapper.getMappedObject(DBObject query, MongoPersistentEntity<?> entity),

Code:

for (String key : query.keySet()) {

        if (Keyword.isKeyword(key)) {
                result.putAll(getMappedKeyword(new Keyword(query, key), entity));
                continue;
        }

        Field field = entity == null ? new Field(key) : new MetadataBackedField(key, entity, mappingContext);

        Object rawValue = query.get(key);
        String newKey = field.getMappedKey();

        if (Keyword.isKeyword(rawValue) && !field.isIdField()) {
                Keyword keyword = new Keyword((DBObject) rawValue);
                result.put(newKey, getMappedKeyword(field, keyword));
        } else {
                result.put(newKey, getMappedValue(field, query.get(key)));
        }
}

here it does not check the rawvalue is an string or DBObject before check whether it's an keyword. So, for such an update operation will raise an Exception java.lang.ClassCastException: java.lang.String cannot be cast to com.mongodb.DBObject:
Code:

  mongoTemplate.updateFirst(query, new Update().set("password", "$2a$10$SK4o6VteIjH0Jw1a4eLV6Oe1tSHQ18Fl6WnZ70ob4TSqAwnVHn5AO")
Sorry for my poor english, I help you can understand what I mean.

Viewing all articles
Browse latest Browse all 128

Trending Articles