Announcement Announcement Module
Collapse
No announcement yet.
mongodb Collections are created without any documents in it Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • mongodb Collections are created without any documents in it

    Hi there,

    i'm currently facing the following "problem":

    I am using two different databases to archieve a better overview and a more comfortable way to administrate them: the first is for my production data, the second is a temporary which consists of a huge set of temporary data which is extracted and merged into the first one. it also contains log entries and stuff like that. By using this approach i'm free to drop the second database and recreate it - without touching the production db.

    So my problem is the automatic creation of collections in my productive database meant to contain the temporary data (but logically are never filled with any of this temporary documents).

    Why is that and how could i avoid this behavior?

    For example a more formal explaination, I've got the databases - and collections

    productive.data1
    productive.data2

    and

    temporary.temp1
    temporary.temp2

    spring automatically creates

    productive.data1
    productive.data2
    productive.temp1
    productive.temp2

    Thank you in advance!

  • #2
    What version of Spring Data MongoDB are you using? The 1.1 release resolved an issue that was caused the index creation being triggered for mapping contexts created for different databases. See [0] for details. So if you use the latest 1.1.1.RELEASE that issue might already be solved.

    What does your configuration look like? "Automatic creation", what does that mean actually? Can you find out when the creation actually happens? What triggers it? Any chance you can come up with a test case to reproduce?

    [0] https://jira.springsource.org/browse/DATAMONGO-500

    Comment


    • #3
      Unfortunately i'm already using the 1.1.1.RELEASE. With automatic creation i mean collections are created without having any documents in it - so without any need of them.

      I created a small testcase where this behavior happens: Both Documents (MyDocOne and MyDocTwo) contain an @Indexed annotation on a custom field - they also contain a field of type object. So when i create entity myDocOne and myDocTwo - setting myDocTwo.obj = myDocOne and persist myDocTwo - spring creates a collection myDocOne in template2... this is a bit confusing - i hope the following code gives a better overview.

      App.java

      Code:
      @Component
      public class App 
      {
      	
          public static void main( String[] args )
          {
          	App app = new App();
          	ApplicationContextLoader loader = new ApplicationContextLoader();
          	loader.load(app, "applicationContext.xml");
          	loader.getApplicationContext();
          	
      		MongoTemplate template1;
      		MongoTemplate template2;
          	
          	try {
      			template1 = new MongoTemplate(new Mongo("localhost"), "tmp1");
      			template1.setApplicationContext(loader.getApplicationContext());
      			template2 = new MongoTemplate(new Mongo("localhost"), "tmp2");
      			template2.setApplicationContext(loader.getApplicationContext());
      			
      			MyDocOne one = new MyDocOne("foo", "bar");
      			template1.save(one);
      			
      			MyDocTwo two = new MyDocTwo("foo", "baz");
      			two.setAny(one);
      			template2.save(two);
      			
      		} catch (UnknownHostException e) {
      			e.printStackTrace();
      		} catch (MongoException e) {
      			e.printStackTrace();
      		}
          }
      }
      MyDocOne.java
      Code:
      @Document
      public class MyDocOne {
      
      	@Indexed
      	String a;
      	String b;
      	
      	Object any;
      	
      	
      	public MyDocOne(String a, String b) {
      		super();
      		this.a = a;
      		this.b = b;
      	}
      	public String getA() {
      		return a;
      	}
      	public void setA(String a) {
      		this.a = a;
      	}
      	public String getB() {
      		return b;
      	}
      	public void setB(String b) {
      		this.b = b;
      	}
      	public Object getAny() {
      		return any;
      	}
      	public void setAny(Object any) {
      		this.any = any;
      	}
      }
      MyDocTwo.java
      Code:
      @Document
      public class MyDocTwo {
      
      	@Indexed
      	String a;
      	String b;
      	
      	Object any;
      	
      	public MyDocTwo(String a, String b) {
      		super();
      		this.a = a;
      		this.b = b;
      	}
      	public String getA() {
      		return a;
      	}
      	public void setA(String a) {
      		this.a = a;
      	}
      	public String getB() {
      		return b;
      	}
      	public void setB(String b) {
      		this.b = b;
      	}
      	public Object getAny() {
      		return any;
      	}
      	public void setAny(Object any) {
      		this.any = any;
      	}
      	
      }

      Comment

      Working...
      X