I am using R to access a MongoDb table which contain records from Google Directions API. While I am able to access the _id values, I receive an error when trying to access a different key in the database data, - which is an array containing all of the information about routes. Any idea how to query an array using rmongodb?
In the code below, first I check how many records are in the collection. Then using mongo.distinct() I query the database for all of the object ids, and then I run into a problem when I try to access the next index - data. Any idea why this is happening? I have included an image with information about both indices from MongoDB compass.
> if(mongo.is.connected(mongo) == TRUE) {
+ help("mongo.count")
+ mongo.count(mongo, coll)
+ }
[1] 106500
> res <- mongo.distinct(mongo, coll, "_id")
> head(res)
$`0`
{ $oid : "57583d1057aa3d0499a85aab" }
$`1`
{ $oid : "57583d1157aa3d0499a85aad" }
$`2`
{ $oid : "57583d1257aa3d0499a85aaf" }
$`3`
{ $oid : "57583d1357aa3d0499a85ab1" }
$`4`
{ $oid : "57583d1457aa3d0499a85ab3" }
$`5`
{ $oid : "57583d1557aa3d0499a85ab5" }
> res <- mongo.distinct(mongo, coll, "data.legs")
Warning message:
In mongo.distinct(mongo, coll, "data.legs")

You should be able to query it exactly as you are trying.
In the absence of your data, here's a working example
In a mongodb client (I'm using Robomongo) we can see data, and that
image_urlis an arraySo your query should work
We can insert more data and run the same query