Search code examples
mongodbmorphia

Morphia Upserting Field as int64 instead of in32


I've written an operation upsert a document to Mongo using Morphia.

I have a field which I want to save as an int32, but after the upsert it is inserted as int64.

I have made sure that I convert the long as an int using Long.intValue() and the object that Morphia serializes back to, the member field is int. I have also checked the UpdateOperations.ops to see what morphia is upserting.

The upsert operation is:

UpdateOperations<Test> ops = datastore.createUpdateOperations(Test.class)
  .set("test_field", testField.intValue())

The current version of Mongo I am using is 3.0.

Any help would be appreciated!

Thanks!

EDIT: Looking at the update query operation in Morphia it is:

{$set={test_field=11}}

Solution

  • I managed to find out the solution. The query for the upsert was querying on the test_field as a long rather than an int. Mongo 3.0 sees this as the type to insert - however running on Mongo 3.2, there is no issue and it will upsert with the type specified in the upsert operation, not the query.