MongoDB: How to lower case all items of an array

Collection name: movie. Field name: actors

db.movie.find().forEach(
function(e) {
for(var i = 0; i < e.actors.length; i++) {
e.actors[i] = e.actors[i].toLowerCase();
}
db.movie.save(e);
}
);
Advertisements

Linux Tip: Delete files older than X days

The following command will delete all files from the current folder that are more than 30 days old

find . -type f -mtime +30 -delete

The following command will delete all files from the folder /backups/ with extension .gz that are more than 5 days old

find /backups/ -type f -name *.gz -mtime +5 -delete

Collections.sublist() not serializable

Ran into a strange serialization issue when trying to add a Java class to memcached…

Caused by:

java.io.NotSerializableException: java.util.RandomAccessSubList
java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1164)
java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1518)
java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1483)
java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1400)
java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1158)
java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:330)
net.spy.memcached.transcoders.BaseSerializingTranscoder.serialize(
BaseSerializingTranscoder.java:105)

The problem was with a class member that was initialized with Collections.sublist() method. This method returns an instance of java.util.RandomAccessSubList which is not serializable.

The solution was to wrap initialize the list as an ArrayList.

new ArrayList<String>(biglist.subList(2, 4))