Announcement Announcement Module
No announcement yet.
MONGODB: index on nested document Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • MONGODB: index on nested document

    I have a need to have one document which contains a nested document. The nested document contains a field for which I would like an index. Here is an example:

    First Document:

    public class LogItem {
        private ObjectId id;
        private String level;
        private String message;
        private StackTrace stackTrace;
    public class StackTrace {
        private string exceptionName;
        private String[] stack;
    What I would expect is the following index definition

    db.logItems.ensureIndex({ "stackTrace.exceptionName" : 1 },{ "name" : "StacktraceExceptionNameIndex" });

    The above is how I can do this in mongo shell.

    I need a way to do this using spring-data and mongo

    Thanks in advance