Skip to content

Instantly share code, notes, and snippets.

@digitalextremist
Last active January 30, 2020 14:36
Show Gist options
  • Save digitalextremist/98406f67aec7eb80226c6f9c27edfbed to your computer and use it in GitHub Desktop.
Save digitalextremist/98406f67aec7eb80226c6f9c27edfbed to your computer and use it in GitHub Desktop.
In lib/mongo/src/bson.cr:228:61
228 | unless LibBSON.bson_append_array_begin(handle, key, key.bytesize, child_handle)
^-------
Error: undefined method 'bytesize' for Array(MessagePack::Type) (compile-time type is (Array(MessagePack::Type) | Bool | Float64 | Hash(MessagePack::Type, MessagePack::Type) | Int16 | Int32 | Int64 | Int8 | String | UInt16 | UInt32 | UInt64 | UInt8 | Nil))
require "msgpack"
require "mongo/bson"
query = {
"age" => {
"$gt" => 30
}
}
#de Native Hash to MessagePack encoded string...
puts msgpack = String.new(query.to_msgpack)
#de Encided string to Hash(String, MessagePack::Type)
query_reborn = Hash(String, MessagePack::Type).from_msgpack(msgpack)
#de The goal:
puts bson = query.to_bson #de Works
puts bson = query_reborn.to_bson #de Throws type-oriented error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment