RejectedSoftware Forums

Sign up

deserializeBson - Json and MongoDB question

Hello all. I am new to vibe.d and web and development in general so my
excuses for any naive questions in advance.
I have this problem with the deserializeBson -Json functions.
When i add new members at my User class i get null_ Bson values for the
not stored fields in the database when i call :

T getUserByName(T)(string name)
{

auto bsonuser = dbcoll.findOne(["name": name]);

auto user = new T();
deserializeBson(user, bsonuser);
return user;

}
(i need 2 subtypes of Users inheriting from User class, Teacher : User,
Student : User)

If i drop the database and create the users again then it works.
Should i make my own deserialization functions? What is the best way to
deal with this so i dont have to drop the database as i extend my User
class.

Re: deserializeBson - Json and MongoDB question

On Fri, 08 Nov 2013 12:18:33 +0100, YiannisOSC wrote:

Hello all. I am new to vibe.d and web and development in general so my
excuses for any naive questions in advance.
I have this problem with the deserializeBson -Json functions.
When i add new members at my User class i get null_ Bson values for the
not stored fields in the database when i call :

T getUserByName(T)(string name)
{

auto bsonuser = dbcoll.findOne(["name": name]);

auto user = new T();
deserializeBson(user, bsonuser);
return user;

}
(i need 2 subtypes of Users inheriting from User class, Teacher : User,
Student : User)

If i drop the database and create the users again then it works.
Should i make my own deserialization functions? What is the best way to
deal with this so i dont have to drop the database as i extend my User
class.

You should write toBson and fromBson functions for Teacher and Student:

Bson toBson() const;
static T fromBson(Bson src);

Re: deserializeBson - Json and MongoDB question

Am 08.11.2013 15:44, schrieb Jack Applegame:

On Fri, 08 Nov 2013 12:18:33 +0100, YiannisOSC wrote:

Hello all. I am new to vibe.d and web and development in general so my
excuses for any naive questions in advance.
I have this problem with the deserializeBson -Json functions.
When i add new members at my User class i get null_ Bson values for the
not stored fields in the database when i call :

T getUserByName(T)(string name)
{

auto bsonuser = dbcoll.findOne(["name": name]);

auto user = new T();
deserializeBson(user, bsonuser);
return user;

}
(i need 2 subtypes of Users inheriting from User class, Teacher : User,
Student : User)

If i drop the database and create the users again then it works.
Should i make my own deserialization functions? What is the best way to
deal with this so i dont have to drop the database as i extend my User
class.
You should write toBson and fromBson functions for Teacher and Student:

Bson toBson() const;
static T fromBson(Bson src);

Or, in the latest GIT master version of vibe.d, you can add a field
"versions": ["VibeNewSerialization"] to your package.json and then add
@optional annotations to the fields that you add later. This will also
work without the "versions" entry soon.