4

I have a Twitter data CSV file which I have read in R using read.table, then I have performed some algorithms on that data and got the output as tabular data. I want to insert this tabular data into mongodb. Can any one help?

The tabular data looks something like this:

pqr
          V2                          V1      V3          V4     polarity   emotion
    1  342521635332_318304224958367   FB   2013-03-15   6:43 PM   positive    <NA>
    2  342521635332_325506614238815   FB   2013-03-08   8:23 PM   neutral     sad
    3  342521635332_347654842010216   FB   2013-02-22   8:13 PM   positive    <NA>
    4  342521635332_567940913224072   FB   2013-02-22   6:27 PM   neutral     <NA>
    5  342521635332_318826431554118   FB   2013-02-22   2:22 PM   positive    joy
    6  342521635332_215298638612191   FB   2013-02-20   8:09 PM   negative    angry
    7  342521635332_407970722630311   FB   2013-02-15   8:48 PM   neutral     joy

mongo.insert(m,'abc.xyz',pqr)

When I am performing mongo insert, the data is getting inserted into mongodb but the data looks like this in mongodb.

db.xyz.find()
    { "_id" : ObjectId("5176273533da42cdbe49f2c5"), "V2" : [ 3, 5, 6, 9, 4, 2, 7, 1, 10, 8 ], "V1" : [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ], "V3" : [ 6, 5, 4, 4, 4, 3, 2, 1, 1, 1 ], "V4" : [ 5, 8, 7, 4, 1, 6, 10, 9, 3, 2 ], "polarity" : [ 3, 2, 3, 2, 3, 1, 2, 2, 3, 1 ], "emotion" : [  -2147483648,    -2147483648,    -2147483648,    -2147483648,    -2147483648,    -2147483648,    1,  -2147483648,    -2147483648,    -2147483648 ] }

I need the data to be inserted into mongodb similar to the tabular data.

Paul Hiemstra
  • 59,984
  • 12
  • 142
  • 149
user2239175
  • 51
  • 1
  • 4

1 Answers1

1

first convert the dataframe to BSON--

b=mongo.bson.from.df(df) then

load the mongo collections using--

mongo.insert(mongo,ns,b)
rrsa
  • 11
  • 6