BSON::InvalidKeyName: key must not contain '.' or '$'

2,805 views
Skip to first unread message

dblock

unread,
Feb 4, 2011, 12:35:59 AM2/4/11
to mongodb-user
We've been getting this error in object save (on Windows) recently
with no code changes. Not sure if the problem is MongoID/bson_ext or
MongoDB, but it's coming from native code somewhere. The error is
BSON::InvalidKeyName: key must not contain '.' (sometimes $). Happens
more frequently with ~100 items with random names generated with a
couple of indexed fields that are similar to the name.

db version v1.6.5, pdfile version 4.5

gems:

bson (1.2.0, 1.1.5)
bson_ext (1.2.0, 1.1.5)
mongo (1.2.0, 1.1.5)
mongoid (2.0.0.rc.1)
mongoid_search (0.1.2)

MongoID thread: http://groups.google.com/group/mongoid/browse_thread/thread/08e192f7d6c85c4f#

Anyone seen this?

Scott Hernandez

unread,
Feb 4, 2011, 12:43:16 AM2/4/11
to mongod...@googlegroups.com
Are you sure your keys don't have those values in them? Do you use
static strings for the key names?

> --
> You received this message because you are subscribed to the Google Groups "mongodb-user" group.
> 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.
>
>

Nat

unread,
Feb 4, 2011, 12:44:46 AM2/4/11
to mongod...@googlegroups.com
How did you generate the random name? even though $ and . are allowed in bson but they should not be used as part of fieldname since it will make the query to be difficult. I think many new drivers disallow it for this purpose. Also please attach the log file / error message, it'll be helpful.

dblock

unread,
Feb 4, 2011, 10:15:43 AM2/4/11
to mongodb-user
Mystery (almost) solved. This is fixed in bson/bson_ext 1.2.0. If
someone knows the exact bug number (if there was one), please share.

http://code.dblock.org/ShowPost.aspx?id=168

Kyle Banker

unread,
Feb 4, 2011, 11:13:01 AM2/4/11
to mongod...@googlegroups.com
Nothing regarding key serialization should have changed between 1.1.5
and 1.2.0. Those exceptions will be generated only when you have '.'
or '$' values in your keys. Just made an issue for showing the invalid
key name:

http://jira.mongodb.org/browse/RUBY-233

This will appear in 1.2.1.

dblock

unread,
Feb 4, 2011, 11:32:11 AM2/4/11
to mongodb-user
@Kyle: no code that I wrote is generating any keys with either . or $
- when I do an insert with mongoid/bson & co., what is generating the
keys?

Kyle Banker

unread,
Feb 4, 2011, 12:17:29 PM2/4/11
to mongod...@googlegroups.com
If you uninstall bson_ext and run your script again, the exception
will include the key name. Alternatively, if you to install bson_ext
from master, you can see the key name that generated the exception.

dblock

unread,
Feb 4, 2011, 12:41:29 PM2/4/11
to mongodb-user
Except I don't get any problems with 1.2.0! I ran it a hundred times.
I swear :)

Drew Miller

unread,
Nov 7, 2012, 9:07:38 PM11/7/12
to mongod...@googlegroups.com
Bah, it must be the name of some key....


On Wed, Nov 7, 2012 at 5:39 PM, xer0x <dre...@gmail.com> wrote:
Okay, I'm getting this error and I swear I haven't changed any of my code. It just popped up after running stable for a month.

Does anyone have more details on what causes this and how to stop it?


This is what we see: (I don't know what icix-robots is..)

[ERROR] Error

Error: key file-icix-robots.key must not contain '.'

    at Error (unknown source)

    at Function.checkKey (./node_modules/mongodb/node_modules/bson/lib/bson/bson.js:1397:11)

    at ./node_modules/mongodb/node_modules/bson/lib/bson/bson.js:350:14

    at ./node_modules/mongodb/node_modules/bson/lib/bson/bson.js:840:23

    at ./node_modules/mongodb/node_modules/bson/lib/bson/bson.js:354:15

    at ./node_modules/mongodb/node_modules/bson/lib/bson/bson.js:840:23

    at ./node_modules/mongodb/node_modules/bson/lib/bson/bson.js:338:15

    at ./node_modules/mongodb/node_modules/bson/lib/bson/bson.js:840:23

    at ./node_modules/mongodb/node_modules/bson/lib/bson/bson.js:354:15

    at ./node_modules/mongodb/node_modules/bson/lib/bson/bson.js:840:23

--
You received this message because you are subscribed to the Google
Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com
To unsubscribe from this group, send email to
mongodb-user...@googlegroups.com
See also the IRC channel -- freenode.net#mongodb

Reply all
Reply to author
Forward
0 new messages