rmongodb

Unable to see collections in mongo DB when connected through R

此生再无相见时 提交于 2020-01-22 00:40:28
问题 I used "rmongodb" package to connect to mongo DB through R. The connection is successful. > mongo.is.connected(mongo) [1] TRUE > If I check at the host where mongoDB is running. > use reporting switched to db reporting > show collections MongoIndexing details test > But from R > mongo.get.database.collections(mongo , db="reporting") character(0) > 回答1: The below code will return an array of collection names iff the provided database has collections in it. Otherwise, it will return character(0

R: data.frame rows to list

倾然丶 夕夏残阳落幕 提交于 2019-12-25 17:17:29
问题 I'm having a data.frame and now I want to convert each row to a list with as keys the column names and values the frame values of that respective row. f <- function(row) { mongo.bson.from.list(row to list) } apply(df, 1, f) the data frame looks like this > h id stamp stmt1 stmt2 stmt3 stmt4 stmt5 stmt6 stmt7 stmt8 1 1 1398288482 "0" "1" "0" "1" "1" "1" "0" "1" 2 2 1398288765 "1" "0" "0" "0" "1" "1" "0" "0" 3 3 1398288804 "1" "1" "1" "1" "1" "1" "1" "1" what I want is an automated way to

Using $or array in query

荒凉一梦 提交于 2019-12-25 09:36:20
问题 I'm trying to query a MongoDB via the R driver rmongodb. The following query works on the cmd line (result: 204,915): db.col1.count( { $or: [ {'status.time':{$gt: ISODate('2013-09-10 00:00:00')}}, {'editings.time':{$gt: ISODate('2013-09-10 00:00:00')}} ] } ); Translating this into R, I tried: d<-strptime('2013-09-10', format='%Y-%m-%d') buf <- mongo.bson.buffer.create() mongo.bson.buffer.start.array(buf, "$or") mongo.bson.buffer.start.object(buf, 'status.time') mongo.bson.buffer.append(buf, "

rmongodb authentication always fails [duplicate]

不羁的心 提交于 2019-12-20 04:27:17
问题 This question already has answers here : rmongodb support for MongoDB 3 (2 answers) Closed 4 years ago . I'm trying to login using rmongodb and it does not authenticate. Here's my connection string: myMongoConnection <- mongo.create(host = "<myip>",db = "geoLoc", username = "<myusername>", password = "<mypassword>") However, if I open a mongo shell on my computer and type: mongo <myip>/geoLoc -u '<myusername>' -p '<mypassword>' it connects just fine. Moreover, if I log into the server and

Transfer large MongoDB collections to data.frame in R with rmongodb and plyr

拜拜、爱过 提交于 2019-12-18 13:42:12
问题 I have some strange results with huge collections sets when trying to transfer as data frames from MongoDB to R with rmongodb and plyr packages. I pick up this code from various github and forums on the subject, and adapt it for my purposes : ## load the both packages library(rmongodb) library(plyr) ## connect to MongoDB mongo <- mongo.create(host="localhost") # [1] TRUE ## get the list of the databases mongo.get.databases(mongo) # list of databases (with mydatabase) ## get the list of the

How to construct rmongodb query using $and operator

血红的双手。 提交于 2019-12-12 02:05:54
问题 I want to use rmongodb to access MongoDB database in R. I tried to construct following query: {'$and': [{_id: {'$gte': '2013-01-01'}}, {_id: {'$lte': '2013-01-10'}}]} I tried three different methods to create bson object, having no luck for all. Method 1: buf = mongo.bson.buffer.create() mongo.bson.buffer.start.array(buf, '$and') mongo.bson.buffer.append(buf, '_id', list('$gte'='2013-01-01')) mongo.bson.buffer.append(buf, '_id', list('$lte'='2013-01-10')) mongo.bson.buffer.finish.object(buf)

r - rmongodb batch insert error: Expected a list of mongo.bson class objects

旧时模样 提交于 2019-12-11 23:46:45
问题 Situation I have a list of athletes lst_ath lst_ath <- structure(list(`1` = structure(c("1125266", "ath_1"), .Names = c("id", "name")), `2` = structure(c("1125265", "ath_2"), .Names = c("id", "name")), `3` = structure(c("1125264", "ath_3"), .Names = c("id", "name")), `4` = structure(c("1125263", "ath_4"), .Names = c("id", "name")), `5` = structure(c("1125262", "ath_5"), .Names = c("id", "name")), `6` = structure(c("1125261", "ath_6"), .Names = c("id", "name")), `7` = structure(c("1125260",

speed up large result set processing using rmongodb

左心房为你撑大大i 提交于 2019-12-09 12:09:35
问题 I'm using rmongodb to get every document in a a particular collection. It works but I'm working with millions of small documents, potentially 100M or more. I'm using the method suggested by the author on the website: cnub.org/rmongodb.ashx count <- mongo.count(mongo, ns, query) cursor <- mongo.find(mongo, query) name <- vector("character", count) age <- vector("numeric", count) i <- 1 while (mongo.cursor.next(cursor)) { b <- mongo.cursor.value(cursor) name[i] <- mongo.bson.value(b, "name")

Inserting json date obeject in mongodb from R

不打扰是莪最后的温柔 提交于 2019-12-08 04:14:14
问题 I am trying to insert forecasted values from a forecasting model along with timestamps in mongodb from. The following code converts the R dataframe into json and then bson. However,when the result is inserted into mongodb, the timestamp is not recognized as date object. mongo1 <-mongo.create(host = "localhost:27017",db = "test",username = "test",password = "test") rev<-data.frame(ts=c("2017-01-06 05:30:00","2017-01-06 05:31:00","2017-01-06 05:32:00","2017-01-06 05:33:00","2017-01-06 05:34:00"

Inserting json date obeject in mongodb from R

℡╲_俬逩灬. 提交于 2019-12-06 16:21:59
I am trying to insert forecasted values from a forecasting model along with timestamps in mongodb from. The following code converts the R dataframe into json and then bson. However,when the result is inserted into mongodb, the timestamp is not recognized as date object. mongo1 <-mongo.create(host = "localhost:27017",db = "test",username = "test",password = "test") rev<-data.frame(ts=c("2017-01-06 05:30:00","2017-01-06 05:31:00","2017-01-06 05:32:00","2017-01-06 05:33:00","2017-01-06 05:34:00"),value=c(10,20,30,40,50)) rev$ts<-as.POSIXct(strptime(rev$ts,format = "%Y-%m-%d %H:%M:%S",tz=""))