Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9257225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:08:11+00:00 2026-06-18T12:08:11+00:00

I’m doing an application to process some data stored in mongoDB using Hadoop .

  • 0

I’m doing an application to process some data stored in mongoDB using Hadoop. I’m writing the program in java.

The thing is that I have a subdocument that contains an array, and I want to take the value of one attribute of the array. I’ll put an example to see it more clear.

 "entities" : {
            "hashtags" : [
                    {
                            "**text**" : "whatever",
                            "indices" : [
                                    59,
                                    69
                            ]
                    },
                    {
                            "**text**" : "whatever",
                            "indices" : [
                                    82,
                                    95
                            ]
                    }
            ],
            "urls" : [ ],
            "user_mentions" : [ ]
    },

The value of the text is the one I want to process.

So I have developed a program in Java and it reports me the following error in the mapper class:

java.lang.ClassCastException: com.mongodb.BasicDBObject cannot be cast to java.lang.String
    at HashTagsMapper.map(HashTagsMapper.java:27)
    at HashTagsMapper.map(HashTagsMapper.java:18)
    at org.apache.hadoop.mapreduce.Mapper.run(Mapper.java:144)
    at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:764)
    at org.apache.hadoop.mapred.MapTask.run(MapTask.java:370)
    at org.apache.hadoop.mapred.Child$4.run(Child.java:255)
    at java.security.AccessController.doPrivileged(Native Method)
    at javax.security.auth.Subject.doAs(Subject.java:415)
    at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1121)
    at org.apache.hadoop.mapred.Child.main(Child.java:249)

This is the mapper class –>

public class HashTagsMapper extends Mapper<Object, BSONObject, Text, IntWritable>
{   
    public void map(Object key, BSONObject value, Context context) throws IOException, InterruptedException
    {

        ArrayList <String> name = new ArrayList<String>();
        BSONObject entities = (BSONObject) value.get("entities");
        BasicDBList hashtags = (BasicDBList) entities.get("hashtags");
        for(int index = 0; index < hashtags.size(); index++){
            name.add((String) hashtags.get(index));
        }
        try{
           FileWriter fw = new FileWriter("/home/jonrodriguez/Hashtags.txt");
           PrintWriter escribirListaRedundantes = new PrintWriter(fw);

           escribirListaRedundantes.println(name);

           fw.close();

        }

           catch(java.io.IOException ioex){}
        for(int i = 0; i < name.size(); i++){
            context.write(new Text(name.get(i)), new IntWritable(1));
        }
    }

Can anyone help me? Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T12:08:12+00:00Added an answer on June 18, 2026 at 12:08 pm

    The problem is the class cast exception. Why don’t you try to write not

    (String)hashtags.get(index)
    

    , but

    hashtags.get(index).toString()
    

    The problem could be that the basicDbList is a List of BDBObjects and you cannot cast the parent to a child.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have thousands of HTML files to process using Groovy/Java and I need to
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am using jsonparser to parse data and images obtained from json response. When
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am using JSon response to parse title,date content and thumbnail images and place
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.