jonhanke
unread,Nov 27, 2010, 11:25:18 AM11/27/10Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to sage-support, jonh...@gmail.com
Hi,
I'm trying to use PyMongo in Sage 4.6, and am having trouble encoding
numbers in dictionary documents, though strings seem to work well.
Any comments are appreciated! Thanks,
-Jon
=)
=============================================
sage: C = pymongo.Connection("localhost:29000")
sage: col = C.db_test.c_test
sage: col
Collection(Database(Connection('localhost', 29000), u'db_test'),
u'c_test')
sage: col.find_one()
sage:
sage: col.insert({ "a" : str(1)})
ObjectId('4cf12d39e1382313ae000010')
sage:
sage: col.insert({ "a" : Integer(1)})
---------------------------------------------------------------------------
InvalidDocument Traceback (most recent call
last)
/home/jonhanke/290_Mongo_code/<ipython console> in <module>()
/usr/local/sage-4.6/local/lib/python2.6/site-packages/pymongo-1.9-
py2.6-linux-x86_64.egg/pymongo/collection.pyc in insert(self,
doc_or_docs, manipulate, safe, check_keys, **kwargs)
268 self.__database.connection._send_message(
269 message.insert(self.__full_name, docs,
--> 270 check_keys, safe, kwargs), safe)
271
272 ids = [doc.get("_id", None) for doc in docs]
/usr/local/sage-4.6/local/lib/python2.6/site-packages/pymongo-1.9-
py2.6-linux-x86_64.egg/pymongo/message.pyc in insert(collection_name,
docs, check_keys, safe, last_error_args)
65 data = __ZERO
66 data += bson._make_c_string(collection_name)
---> 67 bson_data = "".join([bson.BSON.encode(doc, check_keys) for
doc in docs])
68 if not bson_data:
69 raise InvalidOperation("cannot do an empty bulk
insert")
/usr/local/sage-4.6/local/lib/python2.6/site-packages/pymongo-1.9-
py2.6-linux-x86_64.egg/bson/__init__.pyc in encode(cls, document,
check_keys)
460 .. versionadded:: 1.9
461 """
--> 462 return cls(_dict_to_bson(document, check_keys))
463
464 def to_dict(self, as_class=dict, tz_aware=False):
InvalidDocument: Cannot encode object: 1
sage:
sage: col.insert({ "a" : 1})
---------------------------------------------------------------------------
InvalidDocument Traceback (most recent call
last)
/home/jonhanke/290_Mongo_code/<ipython console> in <module>()
/usr/local/sage-4.6/local/lib/python2.6/site-packages/pymongo-1.9-
py2.6-linux-x86_64.egg/pymongo/collection.pyc in insert(self,
doc_or_docs, manipulate, safe, check_keys, **kwargs)
268 self.__database.connection._send_message(
269 message.insert(self.__full_name, docs,
--> 270 check_keys, safe, kwargs), safe)
271
272 ids = [doc.get("_id", None) for doc in docs]
/usr/local/sage-4.6/local/lib/python2.6/site-packages/pymongo-1.9-
py2.6-linux-x86_64.egg/pymongo/message.pyc in insert(collection_name,
docs, check_keys, safe, last_error_args)
65 data = __ZERO
66 data += bson._make_c_string(collection_name)
---> 67 bson_data = "".join([bson.BSON.encode(doc, check_keys) for
doc in docs])
68 if not bson_data:
69 raise InvalidOperation("cannot do an empty bulk
insert")
/usr/local/sage-4.6/local/lib/python2.6/site-packages/pymongo-1.9-
py2.6-linux-x86_64.egg/bson/__init__.pyc in encode(cls, document,
check_keys)
460 .. versionadded:: 1.9
461 """
--> 462 return cls(_dict_to_bson(document, check_keys))
463
464 def to_dict(self, as_class=dict, tz_aware=False):
InvalidDocument: Cannot encode object: 1