RejectedSoftware Forums

Sign up

Error: Expected object instead of array

Hi,

I used to be able to search and display the results on my web page using MongoDB but now I am getting this error:

500 - Internal Server Error

Internal Server Error

Internal error information:
object.Exception@../../.dub/packages/vibe-d-0.7.30/vibe-d/source/vibe/data/bson.d(1433): Expected object instead of array

/usr/include/dmd/phobos/std/exception.d:389 pure @safe void std.exception.bailOut!(Exception).bailOut(immutable(char)[], ulong, const(char[])) [0x833556]
/usr/include/dmd/phobos/std/exception.d:357 pure @safe bool std.exception.enforce!(Exception, bool).enforce(bool, lazy const(char)[], immutable(char)[], ulong) [0x8334d2]
../../.dub/packages/vibe-d-0.7.30/vibe-d/source/vibe/data/bson.d:1433 void vibe.data.bson.BsonSerializer.readDictionary!(vibe.data.serialization.T20deserializeValueImplTS4vibe4data4bson14BsonSerializerS404vibe4data13serialization13DefaultPolicyZ.deserializeValue!(store.Rating).deserializeValue(ref vibe.data.bson.BsonSerializer).Traits).readDictionary(scope void delegate(immutable(char)[])) [0x88323d]
../../.dub/packages/vibe-d-0.7.30/vibe-d/source/vibe/data/serialization.d:645 store.Rating vibe.data.serialization.
T20deserializeValueImplTS4vibe4data4bson14BsonSerializerS404vibe4data13serialization13DefaultPolicyZ.deserializeValue!(store.Rating).deserializeValue(ref vibe.data.bson.BsonSerializer) [0x882e03]
../../.dub/packages/vibe-d-0.7.30/vibe-d/source/vibe/data/serialization.d:659 void vibe.data.serialization.T20deserializeValueImplTS4vibe4data4bson14BsonSerializerS404vibe4data13serialization13DefaultPolicyZ.deserializeValue!(store.Tutor).deserializeValue(ref vibe.data.bson.BsonSerializer).lambda3!(immutable(char)[]).lambda3(immutable(char)[]) [0x8821e7]
../../.dub/packages/vibe-d-0.7.30/vibe-d/source/vibe/data/bson.d:1437 _D4vibe4data4bson14BsonSerializer250
T14readDictionaryTS4vibe4data13serialization102T20deserializeValueImplTS4vibe4data4bson14BsonSerializerS404vibe4data13serialization13DefaultPolicyZ36T16deserializeValueTS5store5TutorZ16deserializeValueFKS4vibe4data4bson14BsonSerializerZ6TraitsZ14readDictionaryMFMDFAyaZvZ14foreachbody3MFKAyaS4vibe4data4bson4BsonZi [0x882503]
../../.dub/packages/vibe-d-0.7.30/vibe-d/source/vibe/data/bson.d:710 const(int function(int delegate(ref immutable(char)[], vibe.data.bson.Bson))) vibe.data.bson.Bson.opApply [0xa2ca1b]
../../.dub/packages/vibe-d-0.7.30/vibe-d/source/vibe/data/bson.d:1435 void vibe.data.bson.BsonSerializer.readDictionary!(vibe.data.serialization.
T20deserializeValueImplTS4vibe4data4bson14BsonSerializerS404vibe4data13serialization13DefaultPolicyZ.deserializeValue!(store.Tutor).deserializeValue(ref vibe.data.bson.BsonSerializer).Traits).readDictionary(scope void delegate(immutable(char)[])) [0x882423]
../../.dub/packages/vibe-d-0.7.30/vibe-d/source/vibe/data/serialization.d:645 store.Tutor vibe.data.serialization.T20deserializeValueImplTS4vibe4data4bson14BsonSerializerS404vibe4data13serialization13DefaultPolicyZ.deserializeValue!(store.Tutor).deserializeValue(ref vibe.data.bson.BsonSerializer) [0x8819f3]
../../.dub/packages/vibe-d-0.7.30/vibe-d/source/vibe/data/serialization.d:286 store.Tutor vibe.data.serialization.
T21deserializeWithPolicyTS4vibe4data4bson14BsonSerializerS404vibe4data13serialization13DefaultPolicyTS5store5TutorTS4vibe4data4bson4BsonZ.deserializeWithPolicy(vibe.data.bson.Bson) [0x88197c]
../../.dub/packages/vibe-d-0.7.30/vibe-d/source/vibe/data/serialization.d:253 store.Tutor vibe.data.serialization.deserialize!(vibe.data.bson.BsonSerializer, store.Tutor, vibe.data.bson.Bson).deserialize(vibe.data.bson.Bson) [0x881907]
../../.dub/packages/vibe-d-0.7.30/vibe-d/source/vibe/data/bson.d:1121 store.Tutor vibe.data.bson.deserializeBson!(store.Tutor).deserializeBson(vibe.data.bson.Bson) [0x8818bf]
source/store.d:86 D5store10TutorStore12obtainTutorsMFAyaAyaZ14foreachbody3MFKS4vibe4data4bson4BsonZi [0x88def5]
../../.dub/packages/vibe-d-0.7.30/vibe-d/source/vibe/db/mongo/cursor.d:174 int vibe.db.mongo.cursor.MongoCursor!(immutable(char)[][immutable(char)[]], vibe.data.bson.Bson, ).MongoCursor.opApply(int delegate(ref vibe.data.bson.Bson)) [0x884596]
source/store.d:86 store.Tutor[] store.TutorStore.obtainTutors(immutable(char)[], immutable(char)[]) [0x88de43]
source/fyt.d:186 void fyt.FindYourTutor.getTutors(fyt.FindYourTutor.SearchForm) [0x86f571]
../../.dub/packages/vibe-d-0.7.30/vibe-d/source/vibe/web/web.d:822 void vibe.web.web.handleRequest!("getTutors", void fyt.FindYourTutor.getTutors(fyt.FindYourTutor.SearchForm), fyt.FindYourTutor).handleRequest(vibe.http.server.HTTPServerRequest, vibe.http.server.HTTPServerResponse, fyt.FindYourTutor, vibe.web.web.WebInterfaceSettings) [0x83a447]
../../.dub/packages/vibe-d-0.7.30/vibe-d/source/vibe/web/web.d:185 void vibe.web.web.
T20registerWebInterfaceHTC3fyt13FindYourTutorVE4vibe3web6common11MethodStylei5Z.registerWebInterface(vibe.http.router.URLRouter, fyt.FindYourTutor, vibe.web.web.WebInterfaceSettings).lambda12!(vibe.http.server.HTTPServerRequest, vibe.http.server.HTTPServerResponse).lambda12(vibe.http.server.HTTPServerRequest, vibe.http.server.HTTPServerResponse) [0x831e3c]
../../.dub/packages/vibe-d-0.7.30/vibe-d/source/vibe/http/router.d:268
D4vibe4http6router9URLRouter13handleRequestMFC4vibe4http6server17HTTPServerRequestC4vibe4http6server18HTTPServerResponseZ21T9lambda4TmTAAyaZ9lambda4MFmMAAyaZb [0x91a3ff]
../../.dub/packages/vibe-d-0.7.30/vibe-d/source/vibe/http/router.d:595 const(bool function(immutable(char)[], scope bool delegate(ulong, scope immutable(char)[][]))) vibe.http.router.MatchTree!(vibe.http.router.Route).MatchTree.doMatch [0x91b1f4]
../../.dub/packages/vibe-d-0.7.30/vibe-d/source/vibe/http/router.d:528 bool vibe.http.router.MatchTree!(vibe.http.router.Route).MatchTree.match(immutable(char)[], scope bool delegate(ulong, scope immutable(char)[][])) [0x91aa53]
../../.dub/packages/vibe-d-0.7.30/vibe-d/source/vibe/http/router.d:261 void vibe.http.router.URLRouter.handleRequest(vibe.http.server.HTTPServerRequest, vibe.http.server.HTTPServerResponse) [0x91a0a3]
../../.dub/packages/vibe-d-0.7.30/vibe-d/source/vibe/http/server.d:1906 bool vibe.http.server.handleRequest(vibe.core.stream.Stream, vibe.core.net.TCPConnection, vibe.http.server.HTTPListenInfo, ref vibe.http.server.HTTPServerSettings, ref bool) [0x95366b]
../../.dub/packages/vibe-d-0.7.30/vibe-d/source/vibe/http/server.d:1662 void vibe.http.server.handleHTTPConnection(vibe.core.net.TCPConnection, vibe.http.server.HTTPListenInfo) [0x951c34]
../../.dub/packages/vibe-d-0.7.30/vibe-d/source/vibe/http/server.d:1543 void vibe.http.server.listenHTTPPlain(vibe.http.server.HTTPServerSettings).doListen(vibe.http.server.HTTPListenInfo, bool, bool).
lambda4(vibe.core.net.TCPConnection) [0x9515b0]
../../.dub/packages/vibe-d-0.7.30/vibe-d/source/vibe/core/drivers/libevent2tcp.d:618 void vibe.core.drivers.libevent2tcp.ClientTask.execute() [0xa11085]
../../.dub/packages/vibe-d-0.7.30/vibe-d/source/vibe/core/core.d:592 void vibe.core.core.makeTaskFuncInfo!(void delegate()).makeTaskFuncInfo(ref void delegate()).callDelegate(vibe.core.core.TaskFuncInfo*) [0x8c00a0]
../../.dub/packages/vibe-d-0.7.30/vibe-d/source/vibe/core/core.d:1221 void vibe.core.core.CoreTask.run() [0x99aebe]
??:? void core.thread.Fiber.run() [0xaa8b7f]
??:? fiber_entryPoint [0xaa88e2]
??:? [0xffffffff]

And here is my code:

Tutor[] obtainTutors(string subject, string country)
{
	auto result = c.find(["subjects":subject,"country":country]);
	Tutor[] tutors;
	foreach(doc;result) tutors ~= deserializeBson!Tutor(doc);
	return tutors;
}

and here are the data structures:

struct Tutor
{

string email;
string uname;
string password;
string city;
string province;
string country;
string[] subjects;
string photo;
float rating;
Rating ratings;

}

struct Rating
{

string uname;
string learner;
string comment;
int rating;

}

As you can see, 'subjects' is an array of strings. I don't know if that is the culprit, but I was able to find before. Also, on the MongoDB prompt, I can find them using the same parameters:

db.tutors.find({subjects:"math", country:"Canada"})

{ "id" : ObjectId("58dc7fb68c41a93f4bc15355"), "email" : "reyv@mail.com", "country" : "Canada", "province" : "BC", "uname" : "reyv@vancouver2017mar2920472", "password" : "qwerty", "photo" : "photoids/reyv@mail.com.jpg", "city" : "Vancouver", "rating" : 0, "subjects" : [ "math", "science", "physics" ], "ratings" : [ { "uname" : "", "learner" : "", "comment" : "", "rating" : 0 } ] }
{ "id" : ObjectId("59623adf45a067c13a98ffeb"), "email" : "ma@mail.com", "country" : "Canada", "province" : "ONTARIO", "uname" : "ma@Toronto2017jul910173", "password" : "qwerty", "photo" : "photoids/ma@mail.com.jpg", "city" : "Toronto", "rating" : 0, "subjects" : [ "math", "physics" ], "ratings" : [ { "uname" : "", "learner" : "", "comment" : "", "rating" : 0 } ] }
{ "id" : ObjectId("59623e0745a067c13a98ffec"), "email" : "bom@ba.com", "country" : "Canada", "province" : "ONTARIO", "uname" : "bom@Toronto2017jul9103031", "password" : "qwerty", "photo" : "photoids/bom@ba.com.jpg", "city" : "Toronto", "rating" : 0, "subjects" : [ "math" ], "ratings" : [ { "uname" : "", "learner" : "", "comment" : "", "rating" : 0 } ] }
{ "id" : ObjectId("5962468045a067c13a98ffed"), "email" : "me@ma.com", "country" : "Canada", "province" : "ONTARIO", "uname" : "me@Toronto2017jul911640", "password" : "qwerty", "photo" : "photoids/me@ma.com.jpg", "city" : "Toronto", "rating" : 0, "subjects" : [ "math", "physics" ], "ratings" : [ { "uname" : "", "learner" : "", "comment" : "", "rating" : 0 } ] }
{ "id" : ObjectId("5962527945a067c13a98ffee"), "email" : "ba@ba.com", "country" : "Canada", "province" : "ONTARIO", "uname" : "ba@Toronto2017jul9115745", "password" : "qwerty", "photo" : "photoids/ba@ba.com.jpg", "city" : "Toronto", "rating" : 0, "subjects" : [ "math", "physics" ], "ratings" : [ { "uname" : "", "learner" : "", "comment" : "", "rating" : 0 } ] }

Thanks!

Re: Error: Expected object instead of array

Am 09.07.2017 um 21:07 schrieb Rey Valeza:

Hi,

I used to be able to search and display the results on my web page using MongoDB but now I am getting this error:

(...)

and here are the data structures:

struct Tutor
{
	string email;
	string uname;
	string password;
	string city;
	string province;
	string country;
	string[] subjects;
	string photo;
	float rating;
	Rating ratings;
}

The declaration of the ratings field should be typed Rating[]
instead of just Rating, as the BSON data contains an array of objects
for that field.

The third line of the compiler error message gives a hint that this is
the place where things go wrong: deserializeValue!(store.Rating), but
unfortunately the stack trace is quite hard to read due to the long
template symbol names.

Re: Error: Expected object instead of array

On Sun, 9 Jul 2017 22:55:39 +0200, Sönke Ludwig wrote:

Am 09.07.2017 um 21:07 schrieb Rey Valeza:

Hi,

I used to be able to search and display the results on my web page using MongoDB but now I am getting this error:

(...)

and here are the data structures:

struct Tutor
{
	string email;
	string uname;
	string password;
	string city;
	string province;
	string country;
	string[] subjects;
	string photo;
	float rating;
	Rating ratings;
}

The declaration of the ratings field should be typed Rating[]
instead of just Rating, as the BSON data contains an array of objects
for that field.

The third line of the compiler error message gives a hint that this is
the place where things go wrong: deserializeValue!(store.Rating), but
unfortunately the stack trace is quite hard to read due to the long
template symbol names.

Thanks, Sönke! That solved it!