[SERVER-8196] $type value should be signed extended Created: 16/Jan/13  Updated: 06/Dec/22  Resolved: 11/Jun/18

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

Type: Bug Priority: Minor - P4
Reporter: Scott Hernandez (Inactive) Assignee: Backlog - Query Team (Inactive)
Resolution: Done Votes: 0
Labels: query_triage
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to SERVER-35454 Query system does not fail cleanly fo... Closed
is related to DOCS-11791 bsonspec.org should clarify MinKey ty... External Review
Assigned Teams:
Query
Operating System: ALL
Participants:

 Description   

> db.max.find({_id:{$type:0xff}}) //documented in bsonspec
error: { "$err" : "type not supported for appendMinElementForType", "code" : 10061 }
> db.max.find({_id:{$type:-1}})
{ "_id" : { "$MinKey" : true } }



 Comments   
Comment by David Storch [ 11/Jun/18 ]

kay.kim, I've filed DOCS-11791 described the proposed improvements to bsonspec.org.

Comment by David Storch [ 11/Jun/18 ]

It seems the confusion here is around whether a BSON type byte should be interpreted as a signed or unsigned char. The server's BSON implementation quite clearly treats it as a signed char, and implements the type code for MinKey as -1, not 255. https://docs.mongodb.com/manual/reference/bson-types/ also documents the type code for MinKey as -1. Therefore, I think the server is working as designed.

ian.whalen kay.kim, do you know where I can file an improvement request for http://bsonspec.org/spec.html?

Comment by Asya Kamsky [ 07/Jun/18 ]

http://bsonspec.org/spec.html still says 0xFF is MinKey though our own docs correct state it's -1.
SERVER-35454 is the ticket to make $type:0 query fail with appropriate error message (it currently returns the same message against an indexed field)

0xff behaves differently now:

> db.foo.find({_id:{$type:0xff}})
Error: error: {
	"ok" : 0,
	"errmsg" : "Invalid numerical type code: 255",
	"code" : 2,
	"codeName" : "BadValue"
}

Comment by Scott Hernandez (Inactive) [ 18/Jan/13 ]

The bson spec uses 0xFF as the type value for MinKey : http://bsonspec.org/#/specification

Comment by Eliot Horowitz (Inactive) [ 18/Jan/13 ]

Where is this documented it should work?
The current behavior seems correct to me.

Generated at Thu Feb 08 03:16:48 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.