Results 1 to 4 of 4

Thread: Spring Data or Mongo inserting data when collection is empty

  1. #1
    Join Date
    Aug 2011
    Location
    Williamsport, PA
    Posts
    29

    Default Spring Data or Mongo inserting data when collection is empty

    Hello everyone,

    I'm not sure if this is something that I am doing wrong or if its Spring Data or Mongo.

    I'm writing an app using Spring MVC, Spring Data and MongoDB. When my view requests data via ajax (jQuery) to load a grid, I am expecting no data in my grid when the collection is empty. However, it seems that data is somehow being inserted into the collection. As though its being generated just to fulfill my request.

    Does anyone know if this is normal behavior? If so, could someone please point me to the correct documentation so that I can get this resolved. I really just want to understand whats happening and why.

    Here is a sample of what is inserted.

    Code:
    > db.client.find();
    { "_id" : ObjectId("4f8ede0ba880e70ea03fb9d7"), "_class" : "com.wbc.model.Client", "lastName" : "lastName_0", "firstName"
    : "firstName_0", "middleName" : "middleName_0", "dateOfBirth" : ISODate("2012-04-18T15:43:11Z"), "driversLicenseNbr" : "driversLicen
    seNbr_0" }
    { "_id" : ObjectId("4f8ede0ba880e70ea03fb9d8"), "_class" : "com.wbc.model.Client", "lastName" : "lastName_1", "firstName"
    : "firstName_1", "middleName" : "middleName_1", "dateOfBirth" : ISODate("2012-04-18T15:40:50Z"), "driversLicenseNbr" : "driversLicen
    seNbr_1" }
    { "_id" : ObjectId("4f8ede0ba880e70ea03fb9d9"), "_class" : "com.wbc.model.Client", "lastName" : "lastName_2", "firstName"
    : "firstName_2", "middleName" : "middleName_2", "dateOfBirth" : ISODate("2012-04-18T15:32:12Z"), "driversLicenseNbr" : "driversLicen
    seNbr_2" }
    { "_id" : ObjectId("4f8ede0ba880e70ea03fb9da"), "_class" : "com.wbc.model.Client", "lastName" : "lastName_3", "firstName"
    : "firstName_3", "middleName" : "middleName_3", "dateOfBirth" : ISODate("2012-04-18T15:36:04Z"), "driversLicenseNbr" : "driversLicen
    seNbr_3" }
    { "_id" : ObjectId("4f8ede0ba880e70ea03fb9db"), "_class" : "com.wbc.model.Client", "lastName" : "lastName_4", "firstName"
    : "firstName_4", "middleName" : "middleName_4", "dateOfBirth" : ISODate("2012-04-18T15:39:01Z"), "driversLicenseNbr" : "driversLicen
    seNbr_4" }
    { "_id" : ObjectId("4f8ede0ba880e70ea03fb9dc"), "_class" : "com.wbc.model.Client", "lastName" : "lastName_5", "firstName"
    : "firstName_5", "middleName" : "middleName_5", "dateOfBirth" : ISODate("2012-04-18T15:31:55Z"), "driversLicenseNbr" : "driversLicen
    seNbr_5" }
    { "_id" : ObjectId("4f8ede0ba880e70ea03fb9dd"), "_class" : "com.wbc.model.Client", "lastName" : "lastName_6", "firstName"
    : "firstName_6", "middleName" : "middleName_6", "dateOfBirth" : ISODate("2012-04-18T15:45:30Z"), "driversLicenseNbr" : "driversLicen
    seNbr_6" }
    { "_id" : ObjectId("4f8ede0ba880e70ea03fb9df"), "_class" : "com.wbc.model.Client", "lastName" : "lastName_8", "firstName"
    : "firstName_8", "middleName" : "middleName_8", "dateOfBirth" : ISODate("2012-04-18T15:32:45Z"), "driversLicenseNbr" : "driversLicen
    seNbr_8" }
    { "_id" : ObjectId("4f8ede0ba880e70ea03fb9e0"), "_class" : "com.wbc.model.Client", "lastName" : "lastName_9", "firstName"
    : "firstName_9", "middleName" : "middleName_9", "dateOfBirth" : ISODate("2012-04-18T15:39:03Z"), "driversLicenseNbr" : "driversLicen
    seNbr_9" }
    { "_id" : ObjectId("4f8ede0ca880e70ea03fb9e1"), "_class" : "com.wbc.model.Client", "lastName" : "lastName_2147483647", "fi
    rstName" : "firstName_2147483647", "middleName" : "middleName_2147483647", "dateOfBirth" : ISODate("2012-04-18T15:37:22Z"), "drivers
    LicenseNbr" : "driversLicenseNbr_2147483647" }
    Thanks,
    John

  2. #2
    Join Date
    Apr 2006
    Location
    Dresden, Germany
    Posts
    483

    Default

    Well it seems you're having code somewhere that does the insertions or the collection simply contains that data upfront. You could try declaring a subclass of AbstractMongoEventListener, override onBeforeSave(…) and have a break point in there to see where the call is originally coming from. If that doesn't get triggered the data is simply present int the collection and you might wanna wipe that one out then.

  3. #3
    Join Date
    Aug 2011
    Location
    Williamsport, PA
    Posts
    29

    Default

    Thanks Oliver, when I get home from work today, I'll give that a shot. I'm not pre-initializing things. I wonder if it could be because I extend the PagingAndSortingRepository, and that the collection was created when the application was started. I'll take a look tonight.

    Thanks again
    John

  4. #4
    Join Date
    Aug 2011
    Location
    Williamsport, PA
    Posts
    29

    Default

    Oliver,
    Sorry for the delay. But I e been trying to reproduce the issue without success. I will keep an eye on the app and see if it occurs again. Thanks again for your help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •