Не могу получить плагин GROMM MongoDB, чтобы сохранить новую запись, даже с явным флеймом
-
09-12-2019 - |
Вопрос
Что я знаю: Mongod работает, существует база данных, существует, коллекция существует, я могу делать вставки с помощью консоли MongoDB, а подключение к экземпляру Mongod производится Grails (то есть я могу запросить и так далее). .
Другие детали: Grails 2.01, плагин MongoDB 1.0.0 RC4, плагин Hibernate 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
}
.
Что не работает: я не могу вставлять какие-либо данные через GROMM, даже когда я явно установил Flush to true.
def n = com.company.project.Node(name: "test")
n.save(flush:true)
.
Я также попробовал это в консоли Grails, но нет сообщения об ошибке.Есть что-то, что я сделал не так?
Решение
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.
Другие советы
Have you tried to make your properties nullable? Something like this:
static constraints =
{
someId nullable: true
}
Execute validate() method before save and take a look on the result, most probably there is some constraint error of which you may not know.