Reputation: 1157
I have a yaml file (third party file that I dont have control over). I need to get this into my mongodb. But when I try inserting it into my collection, I get the below exception
java.lang.ClassCastException: java.lang.Double cannot be cast to java.lang.String
Am using snakeyaml to convert my yaml into a Map. One of my nested structure in yaml has keys as double values, and this is what I think is causing the confusion in mongo db.
Am using mongo-java-driver-2.11.3 to interface with mongo
Here is a sample of my yaml file
persons:
- 1st relative:
name: Alice
sons:
- 0:
name: Alice First son
- 0.2:
name: Alice Second son
- 0.3:
name: Alice Third son
- 0.4:
name: Alice Fourth son
- 0.5:
name: Alice Fifth son
And here is my simple code to insert into mongo
Yaml yaml = new Yaml();
Map<String, Object> object = (Map<String, Object>) yaml.load(new FileInputStream\\test.yaml")));
coll.insert(new BasicDBObject(object));
Any ideas on how to get around this would be much appreciated
Thanks K
Upvotes: 0
Views: 570
Reputation: 1157
Apparently, this problem seems to have gone away when I used mongo-java-driver-2.10.0. I had to go to that version because of my play version which is 2.10.0.
Even though am puzzled as to why it has gone away, am happy it is no more an issue.
Upvotes: 0