Jump to content
plv

TFDMongoQuery data type mismatch. Current type [WideString], new type [ADT]

Recommended Posts

Hello all,

 

I'm having an issue with the TFDMongoQuery component, for some collections in my database, it errors on clicking on "Active" in the inspector. Same error when setting Query.Active := True; in code.

 

It's a very simple project, a TFDConnection and a TFDMongoQuery. For some collections. there's no issue and I can bind the query object to a TeeGrid, but for a couple of others, it errors on a property that looks like this:

 

    "sslBindings" : [ 
        {
            "cert" : ObjectId("xxxx"),
            "_id" : ObjectId("yyyy"),
            "domain" : "www.zzzz.com"
        }, 
        {
            "cert" : ObjectId("xxxxx"),
            "_id" : ObjectId("yyyyyy"),
            "domain" : "zzzzz.com"
        }
    ],

 

Enabling Tracing on the connection doesn't return any error.

 

Any help appreciated, thanks!

 

TFDMongoQueryError.thumb.PNG.403fe39ac974ea0cbadb3f173818f2e0.PNG

 

plv

 

 

Share this post


Link to post
2 hours ago, plv said:

Any help appreciated, thanks!

Have you tried using "mapping" fields if using FireDAC components?
The mapping can be done in any of the phases of the hierarchy, that is:

  1. --- FDManager
  2. ------ FDConnection
  3. ------------- FDQuery/Table/etc...
  4. then, you can inform "what it will be the type used as result" (if compatible, of course)

image.thumb.png.872b594bad3e9a6ef174114b6324db54.png

Share this post


Link to post

Thanks programmerDelphi2k for your answer.

 

The problem is I have no idea what property can be present in the collection, and what json structure it's gonna be.

 

23 minutes ago, programmerdelphi2k said:

Have you tried using "mapping" fields if using FireDAC components?
The mapping can be done in any of the phases of the hierarchy, that is:

  1. --- FDManager
  2. ------ FDConnection
  3. ------------- FDQuery/Table/etc...
  4. then, you can inform "what it will be the type used as result" (if compatible, of course)

image.thumb.png.872b594bad3e9a6ef174114b6324db54.png

 

Share this post


Link to post
1 hour ago, plv said:

I have no idea what property can be present in the collection, 

the "MAP" can be used based on "domain name in table" or on "type of fields"... for example: all fields type "WideString" will be used like "AnsiString".., all field named/like "xTimex" (a field type "TIME" in another format)  it will be used like "TimeStamp"  you see?

 

here my sample test done long time ago...

    // in my example I have a field named: FDMemTable1MyFieldSQLTimeStamp
    //
    {
      MytabletestTable.FormatOptions.OwnMapRules := true;
      //
      MytabletestTable.FormatOptions.MapRules.Clear;
      //
      lFDMRules                := MytabletestTable.FormatOptions.MapRules.Add;
      lFDMRules.DisplayName    := 'MyMapToOracleDateTimeStamp';
      lFDMRules.SourceDataType := TFDDataType.dtDateTimeStamp;
      lFDMRules.TargetDataType := TFDDataType.dtDateTimeStamp;
      //
      // default values
      lFDMRules.PrecMax  := -1; // Maximum numeric precision is the maximum number of digits in the number data types
      lFDMRules.PrecMin  := -1; // Minimum numeric precision is the minimum number of digits in the number data types
      lFDMRules.ScaleMax := -1; // Maximum numeric scale is the maximum number of digits after the decimal point in the number data types. Zero specifies an integer data type
      lFDMRules.ScaleMin := -1; // Minimum numeric scale is the minimum number of digits after the decimal point in number data types
      // lFDMRules.SizeMin  := -1; // The length is in characters for ANSI and Unicode string data types and in bytes for byte string data types.
      // lFDMRules.SizeMax  := -1; // The length is in characters for ANSI and Unicode string data types and in bytes for byte string data types
    }
    //
    // see more help in your Help System because exist more than this basic info here!
    //
    {
      If you need a rule to be used by more than one column, then you create a generic rule and
      use the properties "NameMask" and "TypeMask" so that all columns that match the given names
      are reached by the mapping informed above.
    }
    {
      lFDMRules.NameMask := 'colunmname';   // if used for many columns, use the operators as in "LIKE"
      lFDMRules.NameMask := '%columnname%'; // column that contain "colunmname" in its name
      lFDMRules.NameMask := 'colunm_me';    // column that "start" by "column" + "any char" + "me" in the end name
      //
      // The TypeMask property is useful for the databases that support domain based types, such as:
      // InterBase, Firebird and PostgreSQL.
      // lFDMRules.TypeMask have a same format than "NameMask"
      //
    }
    // lFDMRules.NameMask := 'HIRE%'; // all column-name started by "HIRE"

 

Edited by programmerdelphi2k

Share this post


Link to post

Interesting, I'm gonna try with the type of field, thanks!

Share this post


Link to post

Unfortunately, it doesn't work. The problem goes deeper I think, properties can't be array of objects, but only arrays of simple types and the culprit is the Data.DBJson unit who can't parse objects in arrays.

 

I'm stuck, so if anybody knows a workaround...

 

Thanks!

 

plv

Share this post


Link to post
1 hour ago, plv said:

properties can't be array of objects,

look,

  • a JSON Object can contains another objects or array of objects
    • when an array contains another arrays, is like "Master-Details" tables way... then, you can 
      • you can scan any item in an array and verify if objects exist or another items-of-arrays = (Master-Detail)

so, you can use 2 or more Datasets with your relationship.. table2 -> depend table1 record selected

Share this post


Link to post
4 hours ago, Lars Fosdal said:

The JSON looks non-standard.   

JsonLint.com doesn't like it either. It doesn't know how to deal with ObjectId();

 

Can it be that it is BSON?
Ref. https://stackoverflow.com/questions/16586180/typeerror-objectid-is-not-json-serializable

 

 

image.png

Yes, indeed it is, I'm trying to read a MongoDB collection with a TFDMongoQuery but it chokes on that "sslBindings" property, most likely because Data.DBJson unit that can't read arrays of Objects.

 

 

Share this post


Link to post
16 hours ago, programmerdelphi2k said:

look,

  • a JSON Object can contains another objects or array of objects
    • when an array contains another arrays, is like "Master-Details" tables way... then, you can 
      • you can scan any item in an array and verify if objects exist or another items-of-arrays = (Master-Detail)

so, you can use 2 or more Datasets with your relationship.. table2 -> depend table1 record selected

Yes, it makes sense now that I think about it. I'm gonna do some tests. Thanks for your help!

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×