Query exclude/select ignores special built-in fields


Running query in cloud function -

    const {token_id} = request.params;
    const Weapons = Moralis.Object.extend("Weapons");
    const query = new Moralis.Query(Weapons);
    query.equalTo("token_id", token_id.toLowerCase());
    //This also does not works
    //query.select("player", "level", "base", "rarity", "power", "kind", "category", "damage", "bulletSpeed", "range", "reloadSpeed", "moveSpeed", "token_id");
    query.exclude("createdAt", "updatedAt", "objectId", "__type", "className");
    return await query.first();

exclude() does not work for listed fields. Also, selecting needed fields does not hide these fields. Am I using it correctly?

1 Like

Hey @kosta

Try to use aggregate

const { token_id } = request.params;

const pipeline = [
    project: {
      player: 1,
      level: 1,
      base: 1,
      rarity: 1,
      power: 1,
      kind: 1,
      category: 1,
      damage: 1,
      bulletSpeed: 1,
      range: 1,
      reloadSpeed: 1,
      moveSpeed: 1,
      token_id: 1,
    match: { token_id: token_id.toLowerCase() },

const query = new Moralis.Query("User");

return await query.aggregate(pipeline);


Thanks for fast replay. Tried it but it gives error -

    "code": 141,
    "error": "Pipeline stages should only have one key found project, match"

you may need to change the syntax a little, https://stackoverflow.com/questions/43584023/aggregate-pipeline-throws-the-error-a-pipeline-stage-specification-object-must
so that you don’t have both project and match in same { }


Thank you @cryptokid

Your suggestion should solve the problem.

@kosta my bad, I wrote the code from memory :sweat_smile:

1 Like