[SERVER-2051] Disallow empty string keys Created: 02/Nov/10  Updated: 06/Dec/22

Status: Open
Project: Core Server
Component/s: Usability
Affects Version/s: None
Fix Version/s: features we're not sure of

Type: Improvement Priority: Major - P3
Reporter: Scott Hernandez (Inactive) Assignee: Backlog - Query Optimization
Resolution: Unresolved Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to SERVER-3874 Sort and create index don't work for ... Closed
related to SERVER-6852 Disallow empty path components in doc... Backlog
is related to CSHARP-893 MongoDB.Bson.Serialization.Serializer... Closed
is related to SERVER-5944 modifier failure with empty string fi... Closed
is related to SERVER-12674 Possible to end up with an empty stri... Closed
Assigned Teams:
Query Optimization
Participants:

 Description   

Don't allow empty string fields names.

{"":"test"}

It makes it very hard to use in dot-notation or for updates.



 Comments   
Comment by Glenn Maynard [ 08/Mar/12 ]

Eric: That's a separate problem, which appears to be fixed in SERVER-2651.

FWIW, my first impression about this: while it's probably not a great idea to use blank keys, it seems like MongoDB's dot syntax does support it ("foo..x"), and it'd be nice to not introduce more limitations into Mongo's vocabulary compared to JSON's than necessary.

Comment by Eric Sedor [ 23/Nov/11 ]

> db.left.insert({field1: "whatever", "": null, "field2": "test"})
> db.left.insert({field1: "whatever", "blah": null, "field2": "test"})
> db.left.find()
 
{ "_id" : ObjectId("4ecbd79b0bc92511fe2bd457"), "field1" : "whatever", "" : null, "field2" : "test" }
 
{ "_id" : ObjectId("4ecbd7a70bc92511fe2bd458"), "field1" : "whatever", "blah" : null, "field2" : "test" }
 
> db.left.find({"field1": "whatever"})
 
{ "_id" : ObjectId("4ecbd79b0bc92511fe2bd457"), "field1" : "whatever", "" : null, "field2" : "test" }
 
{ "_id" : ObjectId("4ecbd7a70bc92511fe2bd458"), "field1" : "whatever", "blah" : null, "field2" : "test" }
 
> db.left.update({"field1": "whatever"}, {$set: {"field2": "test2"}}, false, true)
 
LEFT_SUBFIELD only supports Object:  not: 10
 
> db.left.remove({"_id": ObjectId("4ecbd79b0bc92511fe2bd457")}) 
> db.left.update({"field1": "whatever"}, {$set: {"field2": "test2"}}, false, true)
> db.left.find()
 
{ "_id" : ObjectId("4ecbd7a70bc92511fe2bd458"), "blah" : null, "field1" : "whatever", "field2" : "test2" }
 
> db.left.insert({field1: "whatever", "": null, "field2": "test"})
> db.left.update({"field1": "whatever"}, {$set: {"field2": "test2"}}, false, true)

This blurb demonstrates the inconsistency between allowing documents to be created with an empty string LEFT_SUBFIELD and the error thrown by updates when provided. Apologies for extra edits for formatting.

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