I have made 4 variables that represents 4 collections: zk1, zk2, zk3, zk4. Using mongolite:
for (i in 1:4) {
name <- paste0("zk", i, sep = "")
collect <- paste0("zk", i, sep = "")
assign(name, mongo(collection = collect, db = "zeko", url = "mongodb://localhost"))
}
Now, in next stages I would like to loop through variables when applying some method. I tried different ways but it always return an error. For example:
for (j in 1:length(zk_vector)) {
j$count()
}
returns an error:
Error in j$count : $ operator is invalid for atomic vectors
I have tried other solutions but unsuccessfully.