String field type

52 views
Skip to first unread message

Stuart Rackham

unread,
Mar 27, 2011, 3:01:27 AM3/27/11
to mong...@googlegroups.com
A big thank you for MongoKit!

And now the inevitable question:
In addition to the unicode field type is there a string one?
I've l read the docs but can't seem to find the answer.

My code is becoming peppered with u'...' and unicode(...) noise and I'm always
forgetting the conversion and getting validation exceptions. I know that MongoDB
stores Unicode but PyMongo seems to handle strings transparently.

Cheers, Stuart

Nicolas Clairon

unread,
Mar 27, 2011, 2:14:34 PM3/27/11
to mong...@googlegroups.com
Hi,

On Sun, Mar 27, 2011 at 9:01 AM, Stuart Rackham <srac...@gmail.com> wrote:
> A big thank you for MongoKit!

Thank you :)

> And now the inevitable question:
> In addition to the unicode field type is there a string one?
> I've l read the docs but can't seem to find the answer.

I recently add the basestring type in authorized types. You can find
it in the devel branch of Mongokit.

https://github.com/namlook/mongokit/commit/0ebc115e850c23d34ce59104c50a9599379691b3

You can add it yourself in your code like this:

class MyDoc(Document):
authorized_types = Document.authorized_types+[basestring]
structure = {...}

> My code is becoming peppered with u'...' and unicode(...) noise and I'm
> always forgetting the conversion and getting validation exceptions. I know
> that MongoDB stores Unicode but PyMongo seems to handle strings
> transparently.

The reason I initialy made Mongokit to accept only unicode strings was
to be sure that strings are correctly encoded and to prevent some
surprises at runtime. But I understand that it could be annoying some
time. Next version will fix that.

N.

Stuart Rackham

unread,
Mar 27, 2011, 5:40:28 PM3/27/11
to mong...@googlegroups.com

On 28/03/11 07:14, Nicolas Clairon wrote:
> Hi,
>
> On Sun, Mar 27, 2011 at 9:01 AM, Stuart Rackham<srac...@gmail.com> wrote:
>> A big thank you for MongoKit!
>
> Thank you :)
>
>> And now the inevitable question:
>> In addition to the unicode field type is there a string one?
>> I've l read the docs but can't seem to find the answer.
>
> I recently add the basestring type in authorized types. You can find
> it in the devel branch of Mongokit.
>
> https://github.com/namlook/mongokit/commit/0ebc115e850c23d34ce59104c50a9599379691b3
>
> You can add it yourself in your code like this:
>
> class MyDoc(Document):
> authorized_types = Document.authorized_types+[basestring]
> structure = {...}

Thanks for such a prompt reply, I switched to the devel branch and it works like
a charm!

Stuart

Sukhitha jayathilake

unread,
Jun 27, 2013, 3:52:44 AM6/27/13
to mong...@googlegroups.com
 Hi,
I know this thread is quite old. But I want to make something clear. Even if we store elements as str , does retrieving that element from db , return it as unicode?
Thanks,

Nicolas Clairon

unread,
Jun 27, 2013, 4:16:12 AM6/27/13
to mong...@googlegroups.com
Yes. MongoKit's behavior is quite the same than pymongo's behavior. If pymongo is return unicode, then MongoKit does.


--
 
---
You received this message because you are subscribed to the Google Groups "MongoKit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongokit+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages