I have a document structure that looks like this:
{
key1:value1,
key2:value2,
key3: [
index0: objectID(...),
index1: [
index0: objectID(...)
]
]
}
I know you can access arrays using Mongo's dot notation, but I am trying to build a query that only selects all records where key3.index1 length is greater than zero.
All documents in this collection will have key3 and key3 will always have an array at index1. In some cases this array will not be empty.
So far I've tried something like this:
db.collection.find({$where: "this.key3.1.length > 0"})
but this doesn't work.
How can I query for documents using the length of a nested array?
EDIT: Sample Data
{
"_id" : ObjectId("57c98fe77fe6f8009401b5d7"),
"arrayOfData" : [
ObjectId("57c98fe87fe6f8009401b5d8"),
[
ObjectId("57c98fe87fe6f8009401b5d9")
]
]
}
The above is the relevant snippet from the document structure. All documents will have this, in some cases the nested array will be empty, in some cases it will not.