Subject: [mongodb-user] Mongo Scala driver datatype
problem.



Hi,

I am using mongoimport tool to import data into a few collections. The format of the CSV file is as follows -

Id.int64(),Sid.string(),EmpId.int64(),ReportsTo.int64()
1567688,1,470114,952373
1523614,2,479876,768371
1889728,3,343985,27278
1180413,4,287233,469726

I have a similar CSV file for offices -

Id.int64(),Sid.string(),City.string(),Country.string()
1,1,Georgia,USA
2,2,Pune,India

I am using the Mongo Scala driver 1.2.1. I try to do the following -

val storeId = doc.getInteger("Id").toLong

to retrieve the value of Id field, which corresponds to a Long value (StoreId) in my class.

This code works fine for the offices collection where data is less. However, it fails for hierarchy collection where I am importing 1 million records with this exception -

java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Integer
[error]         at org.bson.Document.getInteger(Document.java:151)

I fail to understand two things -

1) When I directly try - val storeId = doc.getLong("Id"), I get this exception -

java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Integer
[error]         at org.bson.Document.getInteger(Document.java:151)

So why can't I get the value of the field using getLong, when I've specified in the CSV file that the type of the column has to be int64?

2) How should I get the value of the field? Isn't the behavior odd - sometimes the field is being treated as integer (when there are less number of records - as in offices collection), and sometimes as a long (where there are 1 million records, as in hierarchy collection)?

Thx,
Manoj.

--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
 
For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+unsubscribe@xxxxxxxxxxxxxxxx.
To post to this group, send email to mongodb-user@xxxxxxxxxxxxxxxx.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/052e4115-2b75-462b-b3d1-e6b8398a0a80%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



Programming list archiving by: Enterprise Git Hosting