# What is a nullable property?

While inserting a row into the db empty value fields are not saved. To change this default behaviour - To set an optional value as null in db, define the property as nullable

For example:

If this is the definition of a collection in .kmongo:

collection Employee {
	property name:String
	property designation:String
	property dob:CalendarDate?
}

then, when we insert a row without setting the dob:

def addEmployee(): Unit = {
    val empRow = EmployeeRow(name = "Vivitsa", designation = "HR")
    EmployeeWriter().insert(empRow)
}

the document saved in mongo-db in as below.

{ 
    "_id" : ObjectId("5e2eaa1d7d212407fca1e309"), 
    "name" : "Vivitsa", 
    "designation" : "HR"
}

To set dob as null in db, define dob as a nullable property:




 



collection Employee {
	property name:String
	property designation:String
	property dob:CalendarDate? nullable
	...
}

Now on an insert:

def addEmployee(): Unit = {
    val empRow = EmployeeRow(name = "Vivitsa", designation = "HR")
    EmployeeWriter().insert(empRow)
}

the document will have dob set to null:





 


{ 
    "_id" : ObjectId("5e2eaa3a7d212407fceadcb6"), 
    "name" : "Vivitsa", 
    "designation" : "HR", 
    "dob" : null
}