Search code examples
grailsmongodbgrails-ormgrails-plugingrails-2.0

Can't get the GORM mongodb plugin to save a new record, even with an explicit flush


What I know: mongod is running, the database exists, the collection exists, I can do inserts using the mongodb console, and a connection to the mongod instance is made by Grails (i.e. I can query and so on).

Other details: Grails 2.01, mongodb plugin 1.0.0 RC4, hibernate plugin 2.01, mongodb 2.0.3

class Node {
    static mapWith = "mongo"

    static constraints = {
    }

    ObjectId id
    Integer someId //someId can be null or just non-existent
    String name
}

What doesn't work: I can't insert any data through GORM, even when I explicitly set flush to true.

def n = com.company.project.Node(name: "test")
n.save(flush:true)

I've also tried this out in the Grails console, but there's no error message. Is there anything I've done wrong?


Solution

  • I'm new to Grails so someone else may or may not correct me. Anyways the issue is that the Mongodb GORM plugin by default doesn't allow null values of any fields that you specify in Mongodb domain classes.

    As of now I'm not sure how to override this behavior, but I will update this if I ever figure it out.