0

My question is, how do I get the size of both arrays? I've tried so many things, can't get any of them to work

{
    "_id" : ObjectId("5dc36ebac1f4d52582abc3d1"),
    "array1" : [ 
        {
            "array2" : [ 
                "This is a test!", 
                "test1"
            ]
        }

    ]
}

the array1 and array2 inside the object, that's also inside array1

so, array1 is of size 1, array2 is of size2

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343

1 Answers1

0

For array1 size, you can unwind array1 then use count or length.

db.getCollection("stackans").aggregate([
  {
    $unwind: "$array1"
  }
],function(err ,data){
    console.log(data.length)
});
Ankit Kumar Rajpoot
  • 5,188
  • 2
  • 38
  • 32