LEFT_SUBFIELD only supports Object

539 views
Skip to first unread message

Ryan Mahoney

unread,
Mar 28, 2012, 1:30:15 PM3/28/12
to mongod...@googlegroups.com
Hi All,

This message is for the benefit of anyone who sees this error in the future and to complain to the MongoDB devs  ;)

If you see this error:

LEFT_SUBFIELD only supports Object

Most likely, if you look at the document you are attempting to update (via $set), one of your keys is empty, for example:

{
    "_id" : ObjectId("4e52b5e08ead0e3853320000"),
    "title" : "Something",
    "url" : "http://www.website.org",
    "" : "",
    "tags" : [ "international"]
}

The only way I have corrected it is to update the entire document w/o the empty key remaining in the new replacement-document.

My question to the MongoDB devs is: why was this error even allowed to be inserted in the first place?  How does something like this even happen?

Thanks!

-r

Aaron Westendorf

unread,
Mar 30, 2012, 9:12:02 AM3/30/12
to mongod...@googlegroups.com
We also ran into this problem in 2.0.2 just this week. We're trying to
optimize saving of large documents by writing only the changes, but
we've encountered numerous differences between "$set" and "store" that
are making the transition quite painful (dotted key notation,
RIGHT_SUBFIELD and LEFT_SUBFIELD errors).

I worked around this bug by first calling "$unset" with {"":1} but now
we have a guarantee of 2 operations per save, whereas $unset was
conditional in my first implementation.

-Aaron

> --
> You received this message because you are subscribed to the Google Groups
> "mongodb-user" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/mongodb-user/-/BjEPUjlYBNUJ.
> To post to this group, send email to mongod...@googlegroups.com.
> To unsubscribe from this group, send email to
> mongodb-user...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/mongodb-user?hl=en.

--
Aaron Westendorf
Senior Software Engineer
Agora Games
359 Broadway
Troy, NY 12180
Phone: 518.268.1000
aa...@agoragames.com
www.agoragames.com

Scott Hernandez

unread,
Mar 30, 2012, 10:51:42 AM3/30/12
to mongod...@googlegroups.com
There are many use-cases where "" can be used as a field name but
unfortunately update doesn't support this.

If you look at the bson spec you will see this is a valid field name.
http://bsonspec.org/#/specification

Aaron Westendorf

unread,
Mar 30, 2012, 11:24:05 AM3/30/12
to mongod...@googlegroups.com
It's not that update doesn't support it, it's that update can't
operate on a record where the empty-string key already exists. I was
able to successfully clear the empty key with $unset.

Glenn Maynard

unread,
Mar 30, 2012, 11:24:50 AM3/30/12
to mongod...@googlegroups.com
On Fri, Mar 30, 2012 at 9:51 AM, Scott Hernandez <scotthe...@gmail.com> wrote:
There are many use-cases where "" can be used as a field name but
unfortunately update doesn't support this.

SERVER-2651/SERVER-5227 (fixed in 2.1)?
 
If you look at the bson spec you will see this is a valid field name.
http://bsonspec.org/#/specification

Well, not all BSON documents are actually legal to store (eg. "." in key names).

--
Glenn Maynard


Scott Hernandez

unread,
Mar 30, 2012, 11:42:05 AM3/30/12
to mongod...@googlegroups.com
On Fri, Mar 30, 2012 at 11:24 AM, Glenn Maynard <gl...@zewt.org> wrote:
> On Fri, Mar 30, 2012 at 9:51 AM, Scott Hernandez <scotthe...@gmail.com>
> wrote:
>>
>> There are many use-cases where "" can be used as a field name but
>> unfortunately update doesn't support this.
>
>
> SERVER-2651/SERVER-5227 (fixed in 2.1)?

Yes, that is fixed in 2.1.0 so you won't get that error.

>> If you look at the bson spec you will see this is a valid field name.
>> http://bsonspec.org/#/specification
>
>
> Well, not all BSON documents are actually legal to store (eg. "." in key
> names).

Correct, and we try to keep that down to a minimum. The dot is really
a soft-limit as it just causes problems with queries/indexing. From
the server's point of view it doesn't really matter as long as you
don't reach into that field with some query/expression. We have found
it much easier for users/clients to simply not introduce this
confusion by disallowing it at that level.

> --
> Glenn Maynard

Alex Zylman

unread,
Jun 26, 2013, 5:23:46 PM6/26/13
to mongod...@googlegroups.com
Sorry to revive something old, but I'm seeing a very similar issue in mongo 2.4.3.

I have a document that looks something similar to this, where a key whose name is a blank string is inside a nested document:

{
  "_id": <my id>,
  "data": {
    "": 1,
    "some_field": 2
  }
}

If I try to update "data.some_field" via $set I get "LEFT_SUBFIELD only supports Object: data. not: 2"

I can't do what someone else suggested of $unset because {$unset: {"data.": 1}} results in "Invalid mod field name, may not end in a period"
Reply all
Reply to author
Forward
0 new messages