my question is how I can translate into php the following js code from mongodb :
t.find( { group:3, ‘x.a’:2 }, { ‘x.$’:1 } ).toArray()[0].x.length,
“single object match (array length match)” );
You can find the whole js code at :
Basically what I care about is how can I translate into php toArray()[0].x.length ? I know php has count but I don’t care about that. I have other advanced queries and all of them reduce to this question.
The literal translation of
toArray()[0].x.lengthwould be:Alternatively, it would be easier to use MongoCollection::findOne() in the above example, since we’re only working with the first result and ignoring any others. Rewritten:
I didn’t follow what you mean by “I know php has count but I don’t care about that.” Unless you were referring to MongoCollection::count(), the basic count() is necessary to calculate the length of the array in the returned document.