[DOCS-7854] Document how to check if a field itself is an array Created: 12/May/16  Updated: 30/Oct/23  Resolved: 16/May/17

Status: Closed
Project: Documentation
Component/s: manual
Affects Version/s: None
Fix Version/s: Server_Docs_20231030

Type: Improvement Priority: Major - P3
Reporter: Linda Qin Assignee: Steve Renaker (Inactive)
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
Participants:
Days since reply: 6 years, 38 weeks, 6 days ago

 Description   

Currently when the field is an array, $type operation on that field matches any inner element. { $type : 'array' } on that array field will match if the field has a nested array, and it will not return results where the field itself is an array.

To check if a field is an array and if the array is not empty, we can use the following query:

db.collection.find({"answers.vendor": {$elemMatch: {$exists:true}}})

To return the document if the field is an array (no matter if it empty or not), we can use the following query:

db.collection.find({$or:[{"answers.vendor": {$elemMatch: {$exists:true}}}, {"answers.vendor":[]} ]})

It would be nice to add this to the document.



 Comments   
Comment by Githook User [ 18/May/17 ]

Author:

{u'username': u'steveren', u'name': u'Steve Renaker', u'email': u'steve.renaker@mongodb.com'}

Message: DOCS-7854: Document how to check if a field itself is an array

Signed-off-by: kay <kay.kim@10gen.com>
Branch: master
https://github.com/mongodb/docs/commit/a013b05897d0b192244d2a4dddc27f670e3d10a7

Comment by Githook User [ 14/Mar/17 ]

Author:

{u'username': u'atsansone', u'name': u'Tony Sansone', u'email': u'tony.sansone@mongodb.com'}

Message: (DOCS-7854): Added cacheSizeGB to test install.
Branch: v3.4
https://github.com/10gen/mms-docs/commit/bc312443797651aa11f4fee606e606120a1e685c

Comment by Githook User [ 14/Mar/17 ]

Author:

{u'username': u'atsansone', u'name': u'Tony Sansone', u'email': u'tony.sansone@mongodb.com'}

Message: (DOCS-7854): Added cacheSizeGB to test install.
Branch: master
https://github.com/10gen/mms-docs/commit/8fafc7e82413bd24e9c7b1ff61fc381760a373fb

Generated at Thu Feb 08 07:55:09 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.