编辑包含数据库连接和插入的 R 代码时,我的数据库没有更新。有没有办法在创建后更新我的收藏?
问题:创建后如何更新集合?
我使用我在堆栈上复制的这段代码:
library(mongolite)
mongo_db_user <- "myuseranme"
mongo_db_password <- "mypassword"
mongo_database <- "mydatabase"
mongo_collection <- "mycollection"
mongo_clustername <- "cluster123-abc.mongodb.net"
# the following is the connection string for an Atlas online MongoDB cluster
url_path = sprintf("mongodb+srv://%s:%s@%s/admin",
mongo_db_user, mongo_db_password, mongo_clustername)
mongo_db <- mongo(collection = mongo_collection, db = mongo_database, url = url_path, verbose = TRUE)
data <- data.frame(Date = c("2020-04-21", "2020-04-20"), Returns = c(0.05, 0.02) )
mongo_db$insert(data)
rm(mongo_db)