1

I'm new to MongoDB and I'm creating my first DB using this guide.

There are tons of SO articles already on you and why you can't use "." or "$" in one's keys like this, this, and this. In most cases, people are indeed trying to store keys with periods in them and are trying to find a way around them. I am NOT trying to store any keys with periods and I am letting Mongo create it's own default ID...but am still getting the error. What am I doing wrong?

Here is when I create my object:

article = {"news_source": news_source,
           "url": url,
           "article_text":article_text,
            "article_summary": article_summary,
            "article_keywords": article_keywords,
           "article_title": article_title,
           "article_metadata": article_metadata}

Here is where I try to insert it into the DB for the first time:

article_id = fox_collections.insert_one(article).inserted_id

And this is the ugly error message that I'm getting:

---------------------------------------------------------------------------
InvalidDocument                           Traceback (most recent call last)
<ipython-input-163-160806aafe79> in <module>()
----> 1 article_id = fox_collections.insert_one(article).inserted_id

//anaconda/lib/python2.7/site-packages/pymongo/collection.pyc in insert_one(self, document, bypass_document_validation)
    623             return InsertOneResult(
    624                 self._insert(sock_info, document,
--> 625                              bypass_doc_val=bypass_document_validation),
    626                 self.write_concern.acknowledged)
    627 

//anaconda/lib/python2.7/site-packages/pymongo/collection.pyc in _insert(self, sock_info, docs, ordered, check_keys, manipulate, write_concern, op_id, bypass_doc_val)
    528             return self._insert_one(
    529                 sock_info, docs, ordered,
--> 530                 check_keys, manipulate, write_concern, op_id, bypass_doc_val)
    531 
    532         ids = []

//anaconda/lib/python2.7/site-packages/pymongo/collection.pyc in _insert_one(self, sock_info, doc, ordered, check_keys, manipulate, write_concern, op_id, bypass_doc_val)
    510                                        command,
    511                                        codec_options=self.codec_options,
--> 512                                        check_keys=check_keys)
    513             _check_write_command_response([(0, result)])
    514         else:

//anaconda/lib/python2.7/site-packages/pymongo/pool.pyc in command(self, dbname, spec, slave_ok, read_preference, codec_options, check, allowable_errors, check_keys, read_concern)
    216         # Catch socket.error, KeyboardInterrupt, etc. and close ourselves.
    217         except BaseException as error:
--> 218             self._raise_connection_failure(error)
    219 
    220     def send_message(self, message, max_doc_size):

//anaconda/lib/python2.7/site-packages/pymongo/pool.pyc in _raise_connection_failure(self, error)
    344             _raise_connection_failure(self.address, error)
    345         else:
--> 346             raise error
    347 
    348     def __eq__(self, other):

InvalidDocument: key 'dcterms.modified' must not contain '.'
Community
  • 1
  • 1
Afflatus
  • 2,302
  • 5
  • 25
  • 40

1 Answers1

0

Basically the article_metadata object was a dictionary of other elements and those had periods in it....

So, lesson of this story -- watch out for nested objects formatted like dictionaries or jsons which may have their own set of keys which need to conform to mongo's rules...

Afflatus
  • 2,302
  • 5
  • 25
  • 40