r - How to insert a dataframe to mongodb using rmongodb -


i have following dataframe

enter image description here

how can insert mongodb using rmongodb?

you need create list of json objects, each of inserted mongo db:

library(rjson) df <- data.frame(rowlabels=c("birrarung marr", "bourke street mall (north)", "bourke street mall (south)", "flagstaff station", "flinders st station underpass", "melbourne central", "princes bridge", "sandridge bridge", "state library", "town hall (west)"),                  locationmax = c(8592, 3213, 3127, 138, 4472, 3923, 4595, 1758, 4252, 2926)) df_list <- lapply(split(df, 1:nrow(df)), function(x) mongo.bson.from.json(tojson(x)))  mongo <- mongo.create()                                # connect mongo on localhost if (mongo.is.connected(mongo) == true) {     icoll <- paste(db, "test", sep=".")     mongo.insert.batch(mongo, icoll, df_list)          # insert mongodb     dbs <- mongo.get.database.collections(mongo, db)     print(dbs)     mongo.find.all(mongo, icoll) } 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -