How to use a myCollection.rawCollection.distinct(myField) call on the client side?


#1

I got this so far, but all it does is a console.log server side. How can i use this on the client side?

import { Mongo } from 'meteor/mongo';

export const col_personas = new Mongo.Collection('personas');

if (Meteor.isServer) {

  raw_col_personas.distinct("channel").then(distinctValues => 
    console.log(distinctValues));

#2

On the client side, it’s mini mongo, it doesn’t has that feature (I think so).
You can call a method which return the distinctValues as result.


#3

But if I export this value, then it’s not dynamic, as in, I can’t pass variables to it and it will produce different results, from the client side, right?

That’s what I want to do.


#4

Do you mean reactive?
I think it’s better to create a temporary/cache collection which stores the result of raw_col_personas.distinct("channel"). When channel collection changed, you update this collection.


#5

ok, ill use reactive instead :slight_smile:

How do i trigger the update from the client side? Or is there a better way?


#6

in my apps, there is only way that client can update data: method. So you can add code to that method to update cache collection.
There is another way, on the server you can use https://docs.meteor.com/api/collections.html#Mongo-Cursor-observeChanges to watch the channel collection then call function to update cache collection.


#7

Never read anything about “method” or “cursor”, trying to figure it out from the API manual. You know where I can find running examples? Using the raw collection. I’m gona keep reading. :slight_smile:


#8

So my data is a bunch of individuals with a “department”. Every department has n sub departments. And an individual usually belongs to more than one subdepartment. The sub departments have random names.

So…

UserId: 1
displayName: joe
department: sales
americanClient: disney
europpeanClient: siemens
australianClient: kanguru

I have a million of these, and i want to produce a list of the available distinct departments and sub departments. Mongo distinct is not available directly, and rawCollection distinct only works server side.

How do i do this?