-
Notifications
You must be signed in to change notification settings - Fork 199
Description
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}
- 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}
- 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}