我正在使用mongodb 2.4.3,我无法让mongoexport工作.我用每个命令得到的错误信息是:
"JavaScript execution failed: SyntaxError: Unexpected identifier"
起初我认为问题出在我的查询参数上,这些参数很长.但是find()在查询中运行良好,所以我知道语法没问题.然后,我使用查询创建了一个新集合,并尝试使用以下内容导出集合:
mongoexport --db Oct2012 --collection sept8subset --csv --fields "text","created_at","user.screen_name","user.followers_count" --out sept8.csv
mongoexport --db Oct2012 --collection sept8subset --csv --fields text,created_at,user.screen_name,user.followers_count --out sept8.csv
mongoexport -d Oct2012 -c sept8subset --csv --fields text,created_at,user.screen_name -o sept8.csv
mongoexport --db Oct2012 --collection sept8subset --dbpath ~/db (should need dbpath as mongod instance is running)
mongoexport --db OCt2012 -collection sept8subset -o sept8.txt
mongoexport --db Oct2012 --collection sept8subset
在每种情况下,我得到"JavaScript execution failed: SyntaxError: Unexpected identifier".SyntaxError在哪里?
我正在尝试复制的集合有50,339个对象.如果它对于mongoexport来说太大了,我会从集合中取出5个文件来制作新的集合.然后我尝试使用与上面相同的命令结构导出它们.我仍然得到相同的错误消息.
现在我想知道问题是mongoexport是否无法处理涉及日期的数据.MongoDB文档指出我可能想使用客户端驱动程序编写自己的导出脚本.
有谁知道我的问题在这里?非常感谢你能提供帮助.
我正在尝试使用plyr包中的ddply将函数应用于数据帧,但是我得到了一些我不理解的结果.我有3个关于结果的问题
鉴于:
mydf<- data.frame(c(12,34,9,3,22,55),c(1,2,1,1,2,2)
, c(0,1,2,1,1,2))
colnames(mydf)[1] <- 'n'
colnames(mydf)[2] <- 'x'
colnames(mydf)[3] <- 'x1'
Run Code Online (Sandbox Code Playgroud)
mydf看起来像这样:
n x x1
1 12 1 0
2 34 2 1
3 9 1 2
4 3 1 1
5 22 2 1
6 55 2 2
Run Code Online (Sandbox Code Playgroud)
如果我做:
k <- function(x) {
mydf$z <- ifelse(x == 1, 0, mydf$n)
return (mydf)
}
mydf <- ddply(mydf, c("x") , .fun = k, .inform = TRUE)
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
Error in `$<-.data.frame`(`*tmp*`, "z", value = structure(c(12, 34, 9, …Run Code Online (Sandbox Code Playgroud) 我有一个JSON文件(从mongoDB导出),我想加载到R.文件大小约为890 MB,大约63,000行12个字段.字段是数字,字符和日期.我想最终得到一个63000 x 12数据帧.
lines <- readLines("fb2013.json")
Run Code Online (Sandbox Code Playgroud)
结果:jFile在char类中包含所有63,000个元素,并且所有字段都集中在一个字段中.
每个文件看起来像这样:
"{\"_ id \":\"10151271769737669 \",\"comments_count \":36,\"created_at \":{\"$ date \":1357941938000},\"icon \":\"http:/ /blahblah.gif \",\"likes_count \":450,\"link \":\"http://www.blahblahblah.php \",\"message \":\"我希望我能搞清楚这一点!\",\"page_category \":\"Computers \",\"page_id \":\"30968999999 \",\"page_name \":\"NothingButTrouble \",\"type \":\"photo\",""updated_at \":{\"$ date \":1358210153000}}"
使用rjson,
jFile <- fromJSON(paste(readLines("fb2013.json"), collapse=""))
Run Code Online (Sandbox Code Playgroud)
只有第一行被读入jFile,但有12个字段.
使用RJSONIO:
jFile <- fromJSON(lines)
Run Code Online (Sandbox Code Playgroud)
结果如下:
Warning messages:
1: In if (is.na(encoding)) return(0L) :
the condition has length > 1 and only the first element will be used
Run Code Online (Sandbox Code Playgroud)
同样,只有第一行被读入jFile并且有12个字段.
rjson和RJSONIO的输出看起来像这样:
$`_id`
[1] "1018535"
$comments_count
[1] 0
$created_at
$date
1.357027e+12
$icon
[1] …Run Code Online (Sandbox Code Playgroud)