haxe Serialisation issue with MongoDb identifiers..

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

haxe Serialisation issue with MongoDb identifiers..

sledorze
Hi!
I'm currently using mongodb and Dion's async communication system which uses haxe serialization.
when mongodb adds a new object in a collection, it generates a unique identifier, typically of this shape:

"_id": {
        "$oid": "4eaaa7e7708b5b0100000001"
    }

unfortunately, using haxe serialization does not preseve this id correctly.
printing a unserialized seriallized id gives something like that:

_id : {
  id : Nª§ùp‹[
}

I will dive into it but if you already have an idea about this, please don't hesitate!

Stephane

Reply | Threaded
Open this post in threaded view
|

Re: haxe Serialisation issue with MongoDb identifiers..

sledorze
Ok, so it looks like the Serializer reveals the reaa inner data of the object..
now that no information is lost, got to find how to make that work nicely!

Thanks for all answers!
- just becoming mad - :)

Stephane
Reply | Threaded
Open this post in threaded view
|

Re: haxe Serialisation issue with MongoDb identifiers..

sledorze
In reply to this post by sledorze
Ok, for those that may be interested by the answer:

What haxe serialized was the 12 bytes of the ObjectId.
So, the work around I've made to make it work through the client.

First, reaffect the _id to it's string representation before serialization (you can't use the mechanism haxe provides to overload serialization and unserialization as it's an extern).

Then when using a string id to perform some request; recreate the ObjectId:

var select = { _id : untyped db.bson_serializer.ObjectID(obj._id) };

Stephane
Reply | Threaded
Open this post in threaded view
|

Re: haxe Serialisation issue with MongoDb identifiers..

Tarwin Stroh-Spijer
I am interested!

Which target are you using? (neko / PHP?) - I recently made a PHP target CMS with Mongo that worked really well. The only annoying part was trying to get the ID as a string (had to use Reflection over that stupid ID Object).


Tarwin Stroh-Spijer
_______________________

Touch My Pixel
http://www.touchmypixel.com/
phone: +61 3 8060 5321
_______________________


On Sat, Oct 29, 2011 at 5:42 AM, sledorze <[hidden email]> wrote:
Ok, for those that may be interested by the answer:

What haxe serialized was the 12 bytes of the ObjectId.
So, the work around I've made to make it work through the client.

First, reaffect the _id to it's string representation before serialization
(you can't use the mechanism haxe provides to overload serialization and
unserialization as it's an extern).

Then when using a string id to perform some request; recreate the ObjectId:

var select = { _id : untyped db.bson_serializer.ObjectID(obj._id) };

Stephane

--
View this message in context: http://haxe.1354130.n2.nabble.com/haxe-Serialisation-issue-with-MongoDb-identifiers-tp6940195p6941318.html
Sent from the Haxe mailing list archive at Nabble.com.

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: haxe Serialisation issue with MongoDb identifiers..

sledorze
Javascript (NodeJs)
I'm onto the same issue (trying now an alternative to what I've explained in the previous answer).

On Fri, Oct 28, 2011 at 8:54 PM, Tarwin Stroh-Spijer [via Haxe] <[hidden email]> wrote:
I am interested!

Which target are you using? (neko / PHP?) - I recently made a PHP target CMS with Mongo that worked really well. The only annoying part was trying to get the ID as a string (had to use Reflection over that stupid ID Object).


Tarwin Stroh-Spijer
_______________________

Touch My Pixel
http://www.touchmypixel.com/
phone: <a href="tel:%2B61%203%208060%205321" value="+61380605321" target="_blank">+61 3 8060 5321
_______________________


On Sat, Oct 29, 2011 at 5:42 AM, sledorze <[hidden email]> wrote:
Ok, for those that may be interested by the answer:

What haxe serialized was the 12 bytes of the ObjectId.
So, the work around I've made to make it work through the client.

First, reaffect the _id to it's string representation before serialization
(you can't use the mechanism haxe provides to overload serialization and
unserialization as it's an extern).

Then when using a string id to perform some request; recreate the ObjectId:

var select = { _id : untyped db.bson_serializer.ObjectID(obj._id) };

Stephane

--
View this message in context: http://haxe.1354130.n2.nabble.com/haxe-Serialisation-issue-with-MongoDb-identifiers-tp6940195p6941318.html
Sent from the Haxe mailing list archive at Nabble.com.

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org


If you reply to this email, your message will be added to the discussion below:
http://haxe.1354130.n2.nabble.com/haxe-Serialisation-issue-with-MongoDb-identifiers-tp6940195p6941362.html
To unsubscribe from haxe Serialisation issue with MongoDb identifiers.., click here.



--
Stéphane Le Dorze


Reply | Threaded
Open this post in threaded view
|

Re: haxe Serialisation issue with MongoDb identifiers..

sledorze
In reply to this post by Tarwin Stroh-Spijer
To reaffect the _id to its string representation, I've simply done it like this (works on JS - node target):

untyped data._id = Std.string(data._id);  

Doing it as soon as it is retrieved from the db has the advantage of not considering if your object id is coming back from the client or not when using it in a query.

Stephane