[DOCS-10924] Clarify if 'missing' is a BSON type in $type agg docs. Created: 20/Oct/17  Updated: 30/Oct/23  Resolved: 20/Oct/17

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

Type: Bug Priority: Minor - P4
Reporter: Dario Cantatore Assignee: Allison Reinheimer Moore
Resolution: Fixed Votes: 0
Labels: collector-298ba4e7
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Participants:
Days since reply: 6 years, 12 weeks ago
Story Points: 0.1

 Description   

The bson aggregation type missing is not shown in the docs but used in the examples. Is it a valid type or is there something else we should be using since undefined was deprecated?



 Comments   
Comment by Githook User [ 22/Nov/17 ]

Author:

{'name': 'Allison Moore', 'username': 'schmalliso', 'email': 'allison.moore@10gen.com'}

Message: DOCS-10924: emphasize what happens when the field doesn't exist for $type
Branch: v3.4
https://github.com/mongodb/docs/commit/076ba72f62b3b324dd7a36ca0487b46b15eb8f06

Comment by Githook User [ 22/Nov/17 ]

Author:

{'name': 'Allison Moore', 'username': 'schmalliso', 'email': 'allison.moore@10gen.com'}

Message: DOCS-10924: emphasize what happens when the field doesn't exist for $type
Branch: master
https://github.com/mongodb/docs/commit/126c4cc49e89a8fb7fc8b40af25c2c6f8290cac0

Comment by Dario Cantatore [ 20/Oct/17 ]

Should this technically be a type in the table?

Also, what do the type numbers apply to? Are they used?

Comment by Allison Reinheimer Moore [ 20/Oct/17 ]

dario.cantatore@gmail.com If the field is non-existent then $type returns "missing". We do mention it under the $type heading in "Behavior"

If the argument is a field that is missing in the input document, $type returns the string "missing".

That said, it's super easy to miss, so I'm adding the explanation below the Available Types section as well. Thanks!

Comment by Dario Cantatore [ 20/Oct/17 ]

On this page:
https://docs.mongodb.com/manual/reference/operator/aggregation/type/

On the bottom it has:

{ _id: 0, "a" : "double" }
{ _id: 1, "a" : "array" }
{ _id: 2, "a" : "object" }
{ _id: 3, "a" : "string" }
{ _id: 4, "a" : "long" }
{ _id: 5, "a" : "missing" }

If you had a cond in the group stage and you were checking for existence with something like:

{ $eq: [{ $type: '$aFieldInYourDb' }, 'missing'] }

is this valid for checking for a non existent value/field?

It currently appears to be working correctly in my usage. But it is not listed on the table at the start of the page showing the 21 different types.

Generated at Thu Feb 08 08:01:41 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.