Mongo Sharred Key definition and used in GO lang - mongodb

I have a program where I need to access Mongo Sharred Key from DB collection in Go lang. I retrieve the collection output as
map[string]interface{}
and type cast Mongo Sharred Key. However sometime its definition is int64 and sometime it is only int. So my Go program is getting panic sating
"invalid interface conversion - interface is defined as int but its type is int64".
And when I change its definition to int64 again I am getting same type error for other records. Please help.

Related

How to save Bit(1) field in postgresql from jpa repository spring boot service

I have a code that reads and writes into a table, which has a field of bit(1). When I am reading this table hibernate converts this into boolean just fine but when I try to save to it, it gives me column is type bit but expression is type boolean. I cannot change this field to boolean at db aide.
So far I tried seeling #Type, attribute converter and columnDefinition=Bit but still not working.
Please help
I am trying to save a Boolean value from Java using jpa repo which is Bit(1) field in postgres SQL db but getting error while doing insert or update.When I am reading this table hibernate converts this into boolean just fine but when I try to save to it, it gives me column is type bit but expression is type boolean. I cannot change this field to boolean at db aide.

Gorm Jsonb type stored as bytea

I'm using a locally hosted postgres DB to test queries to a postgres DB in production. The production database has an info field of type jsonb; and I'm trying to mimic this schema locally when using gorm's AutoMigrate. The model I've defined is below:
import "github.com/jinzhu/gorm/dialects/postgres"
type Event struct {
...
Info postgres.Jsonb
...
}
But when I query JSON attributes, e.g. stmt.Where("info->>'attr' = value"), I get the following error:
...
Message:"operator does not exist: bytea ->> unknown", Detail:"", Hint:"No operator matches the given name and argument type(s). You might need to add explicit type casts.",
...
This query works however in the production environment. It seems that the Info field is being stored as bytea instead of jsonb. I'm aware that I can do stmt.Where("encode(info, "escape")::jsonb->>'attr' = value"), but I'd prefer to mimic the production environment more closely (if possible) than change the query to support these unit tests.
I've tried using type tags in the model (e.g. gorm:"type=jsonb") as well as defining my own JSON type implmementing the valuer, scanner, and GormDataTypeInterface as suggested here. None of these approaches have automigrated the type as jsonb.
Is there any way to ensure AutoMigrate creates a table with type jsonb? Thanks!
I was facing the same problem, type JsonB is automigrated to bytea. I solved it by adding the tag gorm:"type:jsonb". It's also mentioned in your question, but you're using gorm:"type=jsonb", which is not correct.

How to query based on a list of DBRef field in Spark SQL

I have a mongo database that contains a list of DBRef objects. I am converting this collection into a data frame in spark.
This gives the below error. Does anyone know how to resolve this error ??
EDIT:: Conversion to dataframe gives following error -> org.codehaus.janino.InternalCompilerException: Two non-abstract methods "public int scala.collection.TraversableOnce.size()" have the same parameter types, declaring type and return type
The error got resolved after upgrading the version of "org.codehaus.janino" to 3.0.9 (previously, I was using 3.0.8).

Postgresql push uuid field to Clickhouse data type error

I am trying to push data from PG-12 to Clickhouse via FDW extension ("clickhouse_fdw") and it gives me error:
SQL Error [HV004]: ERROR: cannot convert constant value to clickhouse
value Hint: Constant value data type: 2950
Sherlocking gave me error in uuid, excepting this field passes on to data transfer. If I cast it to text it gives error, that target field is uuid not text. I am confused. Which data type casting is appropriate here? Please advise DB gurus :) Thanks beforehands.

OrientDB force property type to be string

I'm using OrientDB and trying to create new property after I inserted my data (millions of rows).
I'm trying to create property on V in order to create an index and I'm getting the following error:
The database contains some schema-less data in the property
'V.ACCOUNT_NO' that is not compatible with the type STRING. Fix those
records and change the schema again [ONetworkProtocolHttpDb]
Now part of the fields type is INTEGER but it seems to me that it's very easy to convert the type to STRING.
how can I do it to the entire data?
I tried your case by creating this simple structure in schema-less mode:
These records are a mix of INTEGER and STRING types:
Now you can convert the not string records type by using this query:
UPDATE V SET ACCOUNT_NO = ACCOUNT_NO.asString() WHERE ACCOUNT_NO.type() <> 'STRING'
Output:
About the exception, I got correctly the same error when I try to create a new property V.ACCOUNT_NO of type STRING in schema-full mode and this is correct because the property already exists in the database and contains mixed types of records, although in schema-less mode.
Once all the records were converted, you'll able to create the new property.
Hope it helps