1

I'm using in Spring Boot, *Embedded MongoDB to do build testing. I need some Collections created, some Documents loaded and a function created in the "system.js" Collection to manage a sequence. I couldn't figure out how to do this with properties file (like what happens with H2 db) I tried to do everything via java in the test configuration phase:

  • the creation of the Collections and the loading of the Documents via Java I did it using mongoTemplate.insert(...) (a Document at the time unfortunately, but I'm satisfied)

-for creating the function through Java I HAVE NOT FOUND A SOLUTION

So, i managed to execute these commands with java:

db.createCollection ("dbSequence");
db.dbSequence.insert ({"seq": "subNumber", "value": 1, "_ class": "com.ilsole24ore.ordiniTermed.model.DbSequence"});

this is the function that I create through the mongodb commands but I can't with java:

db.system.js.save ({_ id: 'getNextSequence',
    value: function getNextSequence (seqName) {
       var sequenceDocument = db.dbSequence.findAndModify ({
          query: {seq: seqName},
          update: {$ inc: {value: 1}},
          new: true
       });
       return sequenceDocument.value;
    }
});
  • the next problem is how to call the function

has anyone already had this need? thanks everyone for the help.

pagurix
  • 1,926
  • 1
  • 12
  • 8

0 Answers0