Skip to content

GPMONGODB-202: Problem when updating a mongo domain - two different fields are kept for the same property #289

@graemerocher

Description

@graemerocher

Original Reporter: gabriela
Environment: Not Specified
Version: 1.1.0.GA
Migrated From: http://jira.grails.org/browse/GPMONGODB-202

My domain object is:
{code}
class PersonMongoDomain {
Integer wordCount;
static mapWith = "mongo";

static mapping = {
    collection 'persons';
    wordCount field: 'wc';
}

}
{code}

  1. add a person:

{code}
PersonMongoDomain p = new PersonMongoDomain();
p.wordCount = 100;
p.save();
{code}

As a result, in mongo I have :

{code}
{
"_id" : ObjectId("4fbc94fe2bd79a29b335a038"),
"version" : NumberLong(1),
"wc" : 100
}
{code}

  1. find a person and update the wordCount:

{code}
PersonMongoDomain p1 = PersonMongoDomain.createCriteria().get {
eq('wordCount', 100)
}
p1.wordCount = 200;
p1.save();
{code}

As a result, in mongo I have :

{code}
{
"_id" : ObjectId("4fbc94fe2bd79a29b335a038"),
"version" : NumberLong(2),
"wc" : 200,
"wordCount" : 100
}
{code}
When updating, another field (the long version corresponding to "wc" field, "wordCount", is created which holds the value "wc" had before the update was done. This happens every time an update is done.

E.g.

{code}
PersonMongoDomain p1 = PersonMongoDomain.createCriteria().get {
eq('wordCount', 200)
}
p1.wordCount = 300;
p1.save();

{code}

After the code above is executed, the record in mongo will look like this:

{code}
{
"_id" : ObjectId("4fbc94fe2bd79a29b335a038"),
"version" : NumberLong(2),
"wc" : 300,
"wordCount" : 200
}

{code}

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions