Вопрос

Folks, Having a problem with inserting the following yaml document into MongoDB:

works:

---
URLs: 
  - "http://www.yahoo.com":
    intensity: 5
    port: 80

does not:

---
URLs: 
  - "foo":
    intensity: 5
    port: 80

The only difference is the url. Here is the python code:

    stream = open(options.filename, 'r')
    yamlData = yaml.load(stream)
    jsonData = json.dumps(yamlData)
    io = StringIO(jsonData)
    me = json.load(io)

    ... calling classes, etc, then
    self.appCollection.insert(me)

err:

 bson.errors.InvalidDocument: key 'http://yahoo.com' must not contain '.'

So, what is the correct way to transform this YML file? :)

Thanks!

Это было полезно?

Решение

You cannot use "." in field names (i.e. keys). If you must, then replace occurences of "." with the unicode representation "\uff0E".

Hope this helps.

Другие советы

As the errors says, you have errors in your key. MongoDB uses dot for nested document keys, you cannot have a key that contains dot as part of the key.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top