I'm developing a log register using mongoDB and Java SpringData.
Here MongoDb capped sub-collection talks about mongoDB structure, but I would do with Java. The most important thing it's that I have a document with one or more fields and a capped array.
Is there some method or way in Java to do this?
My object it's like:
user = {
name: String,
latest_messages: [String] (capped to a 100 elements)
}
in Java:
public class MessageLog {
private ObjectId id;
private String name;
private List<Message> messages;
}
Where:
public class Message{
private String text;
private String level;
private Date date;
}
EDIT:
I'm using Java with Spring source (mongodb driver v2.10.1: http://central.maven.org/maven2/org/mongodb/mongo-java-driver/2.10.1/)
messagessize just before save?DBCollection.udpatesecond argument to be like {"$push": ... $slice:-3}}}?