Announcement Announcement Module
No announcement yet.
MongoDB: Indexed fields are not indexed when using another collection name Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • MongoDB: Indexed fields are not indexed when using another collection name

    When I annotate my fields with d it works, as long as I use the default collection name, but if I do all my operations (save, find, remove etc) on another collection name it gets created but without the indexes.

    Also, a default collection (class name) always gets created, even though all operations uses an alternative collection.

    Where do I file a bug for those issues? Can anyone do it in JIRA or are there some other way? I am using mongodb 1.0.0.M4.


  • #2
    I think you just need to annotate the class with the collection you want it to use.

    @Document(collection = "impressions")
    public class Impression {
    private ObjectId id;
    private String name;
    What I think happens is it scans the annotations at startup, and creates the collections and indexes at that time.


    • #3
      The solution with @Document(collection = "impressions") works, if you store the object only in one collection and the name of the collection is different than the default name. If you store an object in multiple collections you have to create the indexes manually. Maybe in such a scenario the annotation approach does not provide any benefit.

      public class UserString {
      	private String id;
      	private String userName;
      mongoTemplate.ensureIndex(new Index("userName", Order.ASCENDING), "customer1.users");
      mongoTemplate.ensureIndex(new Index("userName", Order.ASCENDING), "customer2.users");
    User("ralph"), "customer1.users"); User("stefan"), "customer1.users");
    User("john"), "customer2.users"); User("adam"), "customer2.users");