Skip to content

Iterate inside an Array that is inside of an Array #97

@Mozasf

Description

@Mozasf

Hello!
I´m new in MongoDB world and I need help.
I need to make a R-script and I don´t have so much idea

I have a dataset like this (this is a small sample):

/* 1 */
{
    "_id" : ObjectId("5819ad77d8828e871ce09297"),
    "Date" : 1478077741,
    "Receptor" : "CORMAD",
    "Position" : "02112016",
    "clients" : [ 
        {
            "mac" : "A2:C2:CA:18:F0:5E",
            "vendor" : "",
            "lastSeen" : 1478077746,
            "power" : -80,
            "R" : "",
            "bssid" : "(not associated) ",
            "essid" : [],
            "probedESSID" : [ 
                "any"
            ]
        }, 
        {
            "mac" : "D6:B0:C2:0E:2B:A0",
            "vendor" : "",
            "lastSeen" : 1478077755,
            "power" : -78,
            "R" : "",
            "bssid" : "(not associated) ",
            "essid" : [],
            "probedESSID" : [ 
                "any"
            ]
        }
/* 2 */
{
    "_id" : ObjectId("5819b009d8828e871ce092dc"),
    "Date" : 1478078401,
    "Receptor" : "CORMAD",
    "Position" : "02112016",
    "clients" : [ 
        {
            "mac" : "C0:38:96:86:1E:91",
            "vendor" : "HonHaiPr",
            "lastSeen" : 1478078443,
            "power" : -80,
            "R" : "",
            "bssid" : "0A:18:D6:2B:7F:EB",
            "essid" : [],
            "probedESSID" : [ 
                "any"
            ]
        }, 
        {
            "mac" : "F4:F1:E1:60:73:D2",
            "vendor" : "Motorola",
            "lastSeen" : 1478078410,
            "power" : -78,
            "R" : "",
            "bssid" : "(not associated) ",
            "essid" : [],
            "probedESSID" : [ 
                "JAZZTEL_HY7S"
            ]
        }

I have this script but I need to run inside "clients" arrays and I don't know how.

library(rmongodb);
mongo <- mongo.create()
todays.readings.count <- mongo.count(mongo,"MIURA.AVE")
todays.readings.cursor <- mongo.find(mongo,"MIURA.AVE")

id <- vector("character",todays.readings.count)
Date <- vector("character",todays.readings.count)
Receptor <- vector("numeric",todays.readings.count)
Position<- vector("character",todays.readings.count)
i <- 1;

while (mongo.cursor.next(todays.readings.cursor)) {
 
    cval = mongo.cursor.value(todays.readings.cursor)
    id[i] <- as.character.mongo.oid((mongo.bson.to.list(cval)$`_id`))
    Date[i] <- mongo.bson.value(cval,"Date")
    Receptor[i] <- mongo.bson.value(cval,"Receptor")
    Position[i] <- mongo.bson.value(cval,"Position")
    i <- i + 1
 
  }

Anyone can help me?
Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions