mapping.Mapper with multiple models results in an error

50 views
Skip to first unread message

Yarden Bar

unread,
Apr 28, 2020, 9:49:58 PM4/28/20
to DataStax Node.js Driver for Apache Cassandra Mailing List
Hi all,
Trying to configure a Mapper with multiple models:
 this.mapper = new mapping.Mapper(clientInstance, {
 models
: {
 
ModelA: {
 keyspace
: config.get<string>("storage.config.keyspace"),
 mappings
: new mapping.UnderscoreCqlToCamelCaseMappings(),
 tables
: ["model_a_table"],
 
},
 
ModelB: {
 keyspace
: config.get<string>("storage.config.keyspace"),
 mappings
: new mapping.UnderscoreCqlToCamelCaseMappings(),
 tables
: ["model_b_table"],
 
},
 
}
 
});
 
this.modelAMapper = this.mapper.forModel("ModelA");
 
this.modelBMapper = this.mapper.forModel("ModelB");


This results in the following error:
Error: You must set the Client keyspace or specify the keyspace of the model in the MappingOptions


Same configuration with only ONE model definition, works.

Trying to configure multiple mappers separately for each model, results in the same error.

Appreciate any help.
Yarden

Jorge Bay Gondra

unread,
Apr 29, 2020, 4:02:42 AM4/29/20
to DataStax Node.js Driver for Apache Cassandra Mailing List
Hi,
Have you tried with the keyspace set when you connect the client instance?

For example:

client = new Client({ contactPoints, localDataCenter, keyspace });

On the other hand, it looks like you are configuring a Mapper using a field ModelA and then you want to retrieve the model mapper using "ModelA" string.
Have you tried using the same field for both?

modelAMapper = this.mapper.forModel(ModelA);

Hope it helps,
Jorge

Yarden Bar

unread,
Apr 29, 2020, 10:44:34 AM4/29/20
to DataStax Node.js Driver for Apache Cassandra Mailing List
Hello Jorge,

Yes, I have tried configuring the Client with the Keyspace, same error.

In Typescript, you can configure Object keys as literals and it will work the same as strings.
I did try using "ModelA" and "ModelB" as keys for the ModelConfig, but it results in the same error.

Did you try re-producing this ?

Thank you,
Jordan

Yarden Bar

unread,
Apr 29, 2020, 10:56:00 AM4/29/20
to DataStax Node.js Driver for Apache Cassandra Mailing List

Jorge Bay Gondra

unread,
Apr 29, 2020, 11:10:50 AM4/29/20
to DataStax Node.js Driver for Apache Cassandra Mailing List
Hi,
The Mapper has a good coverage in both integration and unit tests with complex models. The error is hinting that it can't find the mapping information for a model with that name: https://github.com/datastax/nodejs-driver/blob/06eee78ce3d625fc634fc4b8831ae4a251ea80f4/lib/mapping/mapper.js#L93-L97

With that information, my guess is that it's due to some kind of typo or incorrect setting. Can you check setting the keyspace and include one model at a time and then continue troubleshooting from there?

Otherwise, if you provide a small source code sample (without external dependencies like config) I can try it out.

Thanks,
Jorge

Yarden Bar

unread,
Apr 29, 2020, 12:30:52 PM4/29/20
to DataStax Node.js Driver for Apache Cassandra Mailing List
You're right, typo :(
I re-wrote this block and now it works.

Happy its just that :)
Thank you.

Jorge Bay Gondra

unread,
Apr 30, 2020, 5:01:28 AM4/30/20
to DataStax Node.js Driver for Apache Cassandra Mailing List
Glad to hear that you found the issue.

tbh, the error message is not very clear. I think logging messages can help (there is a ticket for that) but I've also filed a ticket for more clear error messages: https://datastax-oss.atlassian.net/browse/NODEJS-607

Thanks!
Reply all
Reply to author
Forward
0 new messages