Mongo Module

Specific Commands

Recipe Test

Add a mongo module to smile project by altering the <projectName>.ksmile file

group basic{
        mongo-module Mongotype(Alldatatype) at com.iteration3.mongotype
}

<module_name>.conf file under conf directory has the database connection information

Collection

1. property represents data type of a column. It could be one of String, Int, Boolean, Long, Double, CalenderDate, DateTime, JustTime or any of the enum or data defined in data-module

collection StringData{
        property str:String
        property stringList:String*
        let computedString:String  //could be ?(optional),*(list)
        let exprComputedString:String = `str`
}
  1. Reference could be any of the other collection defined in mongo module in the project
collection DproperyData{
          property str:String
          reference strData:StringData

  }
  1. index of collecton either up or down
collection IndexData {
property str:String
property  status:Alldatatype::Status
index indexDataIndex "This index is about the indexDataIndex"{
                up str
                down status
        }
}
  1. embedded
collection EmbedbedData {
embedded OneEmbeded "This is OneEmbeded" {
        property line1:String  " This is line1 from oneEmbeded"
        property zip:Int  "This is zip from oneEmbedded"
}
property embedString:String
eproperty oneEmbed:OneEmbeded
eproperty optOneEmbed:OneEmbeded?
eproperty oneEmbedList:OneEmbeded*
eproperty optOneEmbedList:OneEmbeded*
}

Recipes

Every collection mentioned in kmongo file would generate several scala files. For example, StringData collection would get StringDataQuery, StringDataRow,and StringDataUpdate StringDataWriter,StringDataReader,StringDataChecker scala, and there usage are as follows,

For primitive data type query :

StringDataWriter().drop();
StringDataWriter().save(StringDataRow(str = "Some name",stringList=List("Some Name")))

StringDataQuery().str.is("Some name").findOne.get.str
StringDataQuery().str.lessOrEqual("Some name").find
StringDataQuery().str.lessThan("Some name").find
StringDataQuery().str.greaterOrEqual("Some name").find
StringDataQuery().str.greaterThan("Some name").find
StringDataQuery().str.in("Some name").find
StringDataQuery().str.not("Some name").find
StringDataQuery().str.notIn("Some name", "Some Othere name").find
StringDataQuery().str.notIn(List("Some name", "Some Othere name")).find
StringDataQuery().str.exists.find
StringDataQuery().str.notExists.find
StringDataQuery().str.contains("sh").find
StringDataQuery().str.containsIgnoreCase("Some").find
StringDataQuery().str.startsWith("Some").find
StringDataQuery().str.startsWith("Some").find
StringDataQuery().str.containsIgnoreCase("Some").find
StringDataQuery().str.distinct(StringDataReader().db)
StringDataQuery().str.asc.findOne

For the list data type query :

StringDataWriter().drop();
StringDataWriter().save(StringDataRow(str = "Some name",stringList=List("Some Name")))

new StringDataQuery().stringList.nthOne(0, "Some name").findOne.get.stringList
new StringDataQuery().stringList.exists.find
new StringDataQuery().stringList.notExists.find
new StringDataQuery().stringList.size(3).find
new StringDataQuery().stringList.size(2).find
new StringDataQuery().stringList.contains("Some name").find
new StringDataQuery().stringList.containsAll("Some name", "xxx").find
new StringDataQuery().stringList.containsAll("Some name", "yyy").find

For the list data type update :

StringDataWriter().drop();
StringDataWriter().save(StringDataRow(str = "Some name",stringList=List("Some Name")))
val strQuery = StringDataQuery().stringList.nthOne(0, "sss")

StringDataWriter().updateOne(strQuery, StringDataUpdate().stringList.set(List("ttt","qqq")))
StringDataWriter().updateOne(strQuery, StringDataUpdate().stringList.push("aaa"))
StringDataWriter().updateOne(strQuery, StringDataUpdate().stringList.push("ppp", "qqq"))
StringDataWriter().updateOne(strQuery, StringDataUpdate().stringList.addToSet("xxx"))
StringDataWriter().updateOne(strQuery, StringDataUpdate().stringList.addToSet("xxx", "yyy"))
StringDataWriter().updateOne(strQuery, StringDataUpdate().stringList.addToSet("mmm"))
StringDataWriter().updateOne(strQuery, StringDataUpdate().stringList.removeLast())
StringDataWriter().updateOne(strQuery, StringDataUpdate().stringList.removeFirst())
StringDataWriter().updateOne(strQuery, StringDataUpdate().stringList.removeValue("xxx"))
StringDataWriter().updateOne(strQuery, StringDataUpdate().stringList.removeValues(List("aaa", "ppp")))
StringDataWriter().updateOne(strQuery, StringDataUpdate().stringList.unset());

Define computed properties StringDataRowExtn.scala under src dir and they are available :

StringDataWriter().drop();
StringDataWriter().save(StringDataRow(str = "Some name",stringList=List("Some Name")))
StringDataQuery().str.is("Some name").findOne.get.computedString
StringDataQuery().str.is("Runi").findOne.get.exprComputedString // No need to define this, it has a default value in spec

Reference are stored as follows :

  DproperyDataWriter().save(DproperyDataRow(
str = myString, strData_oid = strDPropertyId

All of the above api’s are applicable for Embeded data type, there is one more api :

new EmbedbedDataQuery().oneEmbedList.matchElement(OneEmbededQuery().line1.is("33 Union Square")).find

Test

For each mongo module one test file gets generated under test dir. Write code there to test the module

class <moduleName>TestSuite extends FunSuite with SmilePerTest {
        test("test1", Tag("tag1")) {
}
> test //This will run entire test cases
> test-only *.<ClassName>.scala -- -n <tagName>

Can add your own test files in this directory , Test scala file must extend FunSuite and SmilePerTest To clean up resources using the beforeEach method in test class

override def beforeEach(testData: TestData): Unit = {
        super.beforeEach(testData);
}