issue with mapper

19 views
Skip to first unread message

Pravin Nayak

unread,
Mar 18, 2019, 1:07:02 AM3/18/19
to DataStax Node.js Driver for Apache Cassandra Mailing List
hi,
so i am using the new mapper object in Cassandra-driver but i have to do a find() or get() based on non primary key , but whenever i try i keep getting this promise rejection saying "Filter not matching PKs".
can anyone suggest how to overcome this issue

Alex Ott

unread,
Mar 18, 2019, 4:35:06 AM3/18/19
to nodejs-dr...@lists.datastax.com
Executing queries based on the non-primary key fields is very dangerous from performance point of view, and shouldn't be used except very limited set of the use cases.
If you really need to perform such queries, you need to reconsider your data model...

The documentation lists existing limitations of the mapper: https://docs.datastax.com/en/developer/nodejs-driver-dse/2.0/features/mapper/limitations-and-faq/. Driver also supports mapping with custom queries: https://docs.datastax.com/en/developer/nodejs-driver-dse/2.0/features/mapper/queries/#custom-queries, but you still shouldn't do queries on the non-primary keys only.

--
You received this message because you are subscribed to the Google Groups "DataStax Node.js Driver for Apache Cassandra Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs-driver-u...@lists.datastax.com.


--
With best wishes,                    Alex Ott
http://alexott.net/
Twitter: alexott_en (English), alexott (Russian)

Jorge Bay Gondra

unread,
Mar 18, 2019, 4:36:24 AM3/18/19
to nodejs-dr...@lists.datastax.com
Hi,
The Node.js Mapper supports querying using partition and clustering keys and it doesn't support generation for queries with "ALLOW FILTERING".
Filtering on non-primary keys is usually an anti-pattern in Apache Cassandra: https://docs.datastax.com/en/developer/nodejs-driver/4.0/features/mapper/limitations-and-faq/

If you have to execute a query with allow filter, the Mapper allows bypassing query generation and use your own query: https://docs.datastax.com/en/developer/nodejs-driver/4.0/features/mapper/queries/#custom-queries

Create your own ModelMapper method with mapWithQuery()
// Write your own query using query markers for parameters
const query = 'SELECT * FROM user_videos WHERE name = ? ALLOW FILTERING';

// Create a new ModelMapper method with your own query
// and a function to extract the parameters from an object 
videoMapper.getByName = videoMapper.mapWithQuery(query, video => [ video.name ]);

Execute it each time
const result = await videoMapper.getByName({ name });

Note that executing this query is not a good idea as it will have unpredictable performance.

Thanks,
Jorge

On Mon, Mar 18, 2019 at 6:07 AM Pravin Nayak <pra12...@gmail.com> wrote:
--
Reply all
Reply to author
Forward
0 new messages