🧵distinct()

Example

import { Model, Schema, Types } from 'cherry3';

const schema = Schema({
name: String,
surname: Types.String,
age: Types.Number,
classNumber: Number,
achievements: { type: Array, default: [] },
closeFriends: Object
});

const model = new Model('classList',schema)

(async() => {

var updateData = await model.updateOne({},{ $push:{
achievements: ["five","so","bes","five","so"]
}},{ $upsert: true });

var result = await model.distinct("achievements");
console.log(result);
/*
["five","so","bes","five","so"]
*/

var resultWithGroup = await model.distinct("achievements",true);
console.log(resultWithGroup);
/*
["five","so","bes"]
*/


})();

Last updated