[DOCS-12194] $type documentation should elaborate on behavior for string types Created: 12/Nov/18  Updated: 30/Oct/23  Resolved: 10/Sep/19

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

Type: Task Priority: Minor - P4
Reporter: Harshad Dhavale Assignee: Nathan Contino (Inactive)
Resolution: Fixed Votes: 0
Labels: docs-onboarding-candidate
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Participants:
Days since reply: 4 years, 22 weeks, 1 day ago
Epic Link: DOCSP-1769
Story Points: 0.1

 Description   

Description

{$type: 2} finds the documents where the value of the field contains a string. Note that the string can be:

  • within an array of strings or
  • within an array containing strings as well as other data types or
  • just by itself

and {$type: 2} and $type will still return the document containing that array. For example:

  

//Second document in this collection contains an Array which has Strings as well as an Object and a Number
 MongoDB Enterprise m0TestingCluster-shard-0:PRIMARY> db.ct.find()
 { "_id" : ObjectId("5be9f1a183dce127c984e8ca"), "conditions" : "ABC" }
 { "_id" : ObjectId("5be9f1a183dce127c984e8cb"), "conditions" : [ "XXX", "YYY", 1, ObjectId("5be60a03562d7b721fd9395f") ] }
 { "_id" : ObjectId("5be9f1a183dce127c984e8cc"), "conditions" : [ 1, 2 ] }
 { "_id" : ObjectId("5be9f1a183dce127c984e8cd"), "conditions" : [ ] }
 
//{$type: 2} will return the second document as shown here
 MongoDB Enterprise m0TestingCluster-shard-0:PRIMARY> db.getCollection('ct').find({conditions:{$type: 2}})
 { "_id" : ObjectId("5be9f1a183dce127c984e8ca"), "conditions" : "ABC" }
 { "_id" : ObjectId("5be9f1a183dce127c984e8cb"), "conditions" : [ "XXX", "YYY", 1, ObjectId("5be60a03562d7b721fd9395f") ] }

 

 Currently, our documentation on $type does not mention this behavior. This leads to some confusion, as some users expect {$type: 2} to return documents that contain the string in a field just by itself.

This request is for a doc update, so that our doc clearly mentions the above behavior.

 

Scope

  • Test the behavior above for 4.2, 4.0, and 3.6
  • Add a new section under Behavior on String, after 'Available Types'.
  • Document the behavior stated above
  • Backport to all versions where behavior is consistent

External Review should be someone on Query.



 Comments   
Comment by Githook User [ 10/Sep/19 ]

Author:

{'username': 'nathan-contino-mongo', 'email': 'nathan.contino@mongodb.com', 'name': 'nathan-contino-mongo'}

Message: DOCS-12194: array matching clarification
Branch: master
https://github.com/mongodb/docs/commit/2786f87ba1cad5bef90c9af7634526fd0d8cd529

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