문제

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