[SERVER-2017] Query for field names in a collection Created: 27/Oct/10  Updated: 06/Dec/22  Resolved: 04/Dec/17

Status: Closed
Project: Core Server
Component/s: Admin
Affects Version/s: None
Fix Version/s: None

Type: New Feature Priority: Minor - P4
Reporter: Thomas Tucker Assignee: Backlog - Query Team (Inactive)
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
Assigned Teams:
Query
Backwards Compatibility: Fully Compatible
Participants:

 Description   

Often I would like to see what fields are defined in a collection. Especially when doing maintenance in the shell.
something like
db.mycollection.getFields()
to return all defined fields in all docs of a collection
or
db.mycol.getFields(

{Field2 : 1}

)
get all fields from docs where Field2 is defined in the doc
or
db.mycol.findFields(

{docType : "orderitems"}

)
get all fields from docs where the docType Field is defined and contains the value of "orderitems"



 Comments   
Comment by Asya Kamsky [ 04/Dec/17 ]

Doable via aggregation as of 3.4.4.

Comment by Asya Kamsky [ 04/Dec/17 ]

This is possible to do in aggregation using "$objectToArray" (available in 3.4.4) - there is a write-up showing how to do it here for top level keys: http://www.askasya.com/post/getallkeys/.

Generated at Thu Feb 08 02:58:43 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.