我在数据库“mydb”中的集合“bd”中有我的数据。它的亚马逊评论数据,我关心“产品/产品ID”字段和与之相关的数据
#loading rmongodb library
library(rmongodb)
mongo <- mongo.create()
if(mongo.is.connected(mongo) == TRUE)
{
#selecting mydb database
db <- "mydb"
mongo.get.database.collections(mongo, db)
}
#selecting bd collection in mydb
coll = "mydb.bd"
#putting all productId in the res variable
if(mongo.is.connected(mongo) == TRUE)
{
#since there are duplicate values of "product/productId" field,i stored only unique values of it
res <- mongo.distinct(mongo, coll, "product/productId")
}
#logic to get review blob for a particular productId and here is where i get error
if (mongo.is.connected(mongo) == TRUE)
{
for(i in 1:length(res))
{
#getting error here while iterating for each productId stored in res[i]
doc <- mongo.find.all(mongo,coll,'{"product/productId": res[i]}')
}
}
#but i get error in here as==>
#Error in mongo.bson.from.JSON(arg) :
#Not a valid JSON content: {"product/productId": res[i]}