[SERVER-6078] Wire protocol cannot handle some field names, even though they are not reserved Created: 13/Jun/12  Updated: 21/Apr/17  Resolved: 21/Apr/17

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

Type: Bug Priority: Minor - P4
Reporter: Thilo Planz Assignee: Unassigned
Resolution: Done Votes: 1
Labels: wireprotocol
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
Operating System: ALL
Participants:

 Description   

According to the documentation, only field names starting with `$` are reserved. But it seems that because of how the wire protocol is implemented (looking at what the drivers do, the documentation is a bit sparse here), certain field names take on a special meaning, such as "orderby" or "query":

> db.test.insert({_id:123, orderby: 1, query: 2});
> db.test.insert({_id:124, orderby: 2, query: 1});
> db.test.find({orderby: 1})
  { "_id" : 123, "orderby" : 1, "query" : 2 }
> db.test.find({query: {}, orderby: 1})
  error: { "$err" : "sort must be an object or array", "code" : 13513 }

The wire protocol should be updated to use some kind of different scheme to avoid ambiguity, such as prefixing the special parts of the query with $ as happens in other places.



 Comments   
Comment by Ian Whalen (Inactive) [ 21/Apr/17 ]

This has been confirmed as fixed in 3.4.

Comment by Eser Aygün [ 23/Aug/12 ]

I encountered a related problem.

If I insert a record with a reference field named "query", MongoDB fails to retrieve the object:

> db.item.insert({query: {$ref: "query", $id: ObjectId("50361887352fc04c86af4c10")}})
> db.item.find({query: {$ref: "query", $id: ObjectId("50361887352fc04c86af4c10")}})
>

But, if I change the name of the field to "query_", everything is fine:

> db.item.insert({query_: {$ref: "query", $id: ObjectId("50361887352fc04c86af4c10")}})
> db.item.find({query_: {$ref: "query", $id: ObjectId("50361887352fc04c86af4c10")}})
{ "_id" : ObjectId("503619f0dd2290f4bb17a275"), "query_" : { "$ref" : "query", "$id" : ObjectId("50361887352fc04c86af4c10") } }

It is also fine if the field has a simple non-compound value:

> db.item.insert({query: ObjectId("50361887352fc04c86af4c10")})
> db.item.find({query: ObjectId("50361887352fc04c86af4c10")})
{ "_id" : ObjectId("50361b44dd2290f4bb17a276"), "query" : ObjectId("50361887352fc04c86af4c10") }

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