When I am creating a simple object and just calling save method on that object, all the attributes which are nullable true are inserted into the database with null value. This is just creating clutter in the database. Is there a way to avoid this?
- Grails version - 2.5.6
- GORM version - 6.0.12
- mongodb.engine = "mapping"
Domain :
public class Person {
static constraints = {
name(nullable: true)
telecom(nullable: true)
gender(nullable: true)
birthDate(nullable: true)
address(nullable: true)
}
}
Code :
Person person = new Person()
person.save()
Mongo db entry
{
"_id" : NumberLong(59),
"address" : null,
"birthDate" : null,
"gender" : null,
"name" : null,
"telecom" : null,
"version" : 0,
"dateCreated" : ISODate("2020-04-18T15:34:26.244Z"),
"lastUpdated" : ISODate("2020-04-18T15:34:26.244Z")
}
Expected Entry in database :
{
"_id" : NumberLong(59),
"version" : 0,
"dateCreated" : ISODate("2020-04-18T15:34:26.244Z"),
"lastUpdated" : ISODate("2020-04-18T15:34:26.244Z")
}
This used to work with the older versions of GORM, this was the default behaviour, but when I updated the version of GORM, I started getting all these null values in the database, which is just increasing the size of my database.