RejectedSoftware Forums

Sign up

Incompatible types in MongoDB array

I have the following code:

 fwColl.update(
			["_id":BsonObjectID.fromString(fwID)],
			["$push":[
				  "elections":[
					       "id":propositionID,
					       "propName":propositionPage["proposal"].get!string,
					       "vote":resp
					       ]
				  ]
			 ]
			);

which return the error:

source/synd/voting.d(290): Error: incompatible types for ((propositionID) : (resp)): 'string' and 'bool'

On the MongoDB website, I see that they mix different types within an array (e.g. one value is a string, the other an int). Is there a special way to do this in Vibe that I haven't noticed or am I just going about it completely wrong.

Re: Incompatible types in MongoDB array

It isn't a MongoDB or Vibe.d issue.
In D language you can not create associative array with different types of values.
To fix it just serialize all values to BSON:

fwColl.update(
    ["_id":BsonObjectID.fromString(fwID)],
        ["$push":[
	    "elections":[
                "id": propositionID.serializeToBson,
                "propName": propositionPage["proposal"].get!string.serializeToBson,
                "vote": resp.serializeToBson
            ]
        ]
    ]
);