As of April 12th, you must go to Progress SupportLink to create new support cases or to access existing cases. Please, bookmark the SupportLink URL and use the new portal to contact the support team.
using GROUP collection to get list of all unique values
J
Juraj
started a topic
about 5 years ago
Hello,
I am Kinvey beginner. I have my collection, where each item/row within my collection has also value of one room where it belongs to. My point is to display a unique list of all used rooms in my collection. Plus to count how many particular rooms are in the collection. It leads to the using of Group method.
Here is how I use that for counting - it is working correctly with {room: body.room} parameter attached in the request body:
However I am suffering how to use GROUP method for how display a unique list of all used rooms in my collection... Any help would be more that appreciated!
Thank you
Best Answer
J
Juraj
said
about 5 years ago
Pranav,
thank you for your response. I read documentation about Kinvey Business Logic - Collection-Access-Module, there are only few words about Group method as a part of the CollectionAccess, and output using test API console gives only limited and general debug message "TypeError: undefined is not a function". However I found that method Distinct works well for this purpose. So if anybody wants to see/send list of all unique items in particular column (i.e. room) in the collection, here is the simple code to put as a part of Custom Endpoint:
function onRequest(request, response, modules) {
modules.collectionAccess.collection('Example').distinct('room', function (err, docs) {
Please go through this documentation on Kinvey "User Groups". Please implement it on Kinvey's API console to get familiar with it.
Thanks,
Pranav
J
Juraj
said
about 5 years ago
Answer
Pranav,
thank you for your response. I read documentation about Kinvey Business Logic - Collection-Access-Module, there are only few words about Group method as a part of the CollectionAccess, and output using test API console gives only limited and general debug message "TypeError: undefined is not a function". However I found that method Distinct works well for this purpose. So if anybody wants to see/send list of all unique items in particular column (i.e. room) in the collection, here is the simple code to put as a part of Custom Endpoint:
function onRequest(request, response, modules) {
modules.collectionAccess.collection('Example').distinct('room', function (err, docs) {
Juraj
Hello,
I am Kinvey beginner. I have my collection, where each item/row within my collection has also value of one room where it belongs to. My point is to display a unique list of all used rooms in my collection. Plus to count how many particular rooms are in the collection. It leads to the using of Group method.
Here is how I use that for counting - it is working correctly with {room: body.room} parameter attached in the request body:
function onRequest(request, response, modules) {
var body = request.body;
modules.collectionAccess.collection('Example').group([], {room: body.room}, {"count":0}, "function (obj, prev) { prev.count++}", function (err, docs) {
if (err) {
logger.error('Query failed: '+ err);
} else {
response.body = docs;
response.complete(200);
}
});
}
However I am suffering how to use GROUP method for how display a unique list of all used rooms in my collection... Any help would be more that appreciated!
Thank you
Pranav,
thank you for your response. I read documentation about Kinvey Business Logic - Collection-Access-Module, there are only few words about Group method as a part of the CollectionAccess, and output using test API console gives only limited and general debug message "TypeError: undefined is not a function". However I found that method Distinct works well for this purpose. So if anybody wants to see/send list of all unique items in particular column (i.e. room) in the collection, here is the simple code to put as a part of Custom Endpoint:
function onRequest(request, response, modules) {
modules.collectionAccess.collection('Example').distinct('room', function (err, docs) {
if (err) {
logger.error('Query failed: '+ err);
} else {
response.body = docs;
response.complete(200);
}
});
}
output:
200 OK
Thanks,
Juraj
- Oldest First
- Popular
- Newest First
Sorted by Oldest FirstPranav J
Juraj,
Please go through this documentation on Kinvey "User Groups". Please implement it on Kinvey's API console to get familiar with it.
Thanks,
Pranav
Juraj
Pranav,
thank you for your response. I read documentation about Kinvey Business Logic - Collection-Access-Module, there are only few words about Group method as a part of the CollectionAccess, and output using test API console gives only limited and general debug message "TypeError: undefined is not a function". However I found that method Distinct works well for this purpose. So if anybody wants to see/send list of all unique items in particular column (i.e. room) in the collection, here is the simple code to put as a part of Custom Endpoint:
function onRequest(request, response, modules) {
modules.collectionAccess.collection('Example').distinct('room', function (err, docs) {
if (err) {
logger.error('Query failed: '+ err);
} else {
response.body = docs;
response.complete(200);
}
});
}
output:
200 OK
Thanks,
Juraj
-
How do I access query string values for GET and DELETE requests?
-
Basic Authentication in Business Logic
-
How do I cascade delete entities from related collections?
-
All BL failing with Violation Error
-
How do I send push notifications?
-
Whenever I try to query by _id, I get zero results
-
receiving SOCKETTIMEDOUT when requesting external http response
-
Unique Constraints on a collection column?
-
Need some help with grouping
-
Accessing Endpoint from Collection Hook
See all 342 topics