Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
graemerocher opened this issue May 23, 2012 · 0 comments

Comments

@graemerocher
Copy link
Member

Original Reporter: gabriela
Environment: Not Specified
Version: 1.1.0.GA
Migrated From: http:https://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}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant