Use the same Schema inside a daughter key with Mongoose

1

I'm working with NodeJS, MongoDB and Mongoose where I'm creating an access permissions system that works with infinite sub-levels. The permissions have the same Schema:

//app/models/PermissaoModel.js

const mongoose = require('mongoose');
const Schema = mongoose.Schema;

var PermissaoSchema = new Schema({
  alias: { type: String, unique: true },
  nome: { type: String, required: true },
  descricao: { type: String, default: '' },
  padrao: { type: Boolean, default: true },
  itens: [PermissaoSchema] // <- aqui está meu problema...
});

module.exports = mongoose.model('Permissao', PermissaoSchema);

//o resultado seria algo como:
permissao:{
  alias,
  nome,
  descricao,
  padrao,
  itens:[permissao, permissao, permissao, permissao, ...]
}

But when trying to create this sub-level structure, my code is making an error saying that I can not use it as a reference ...

How can I create an infinite sub-level structure to work with these permissions?

    
asked by anonymous 17.01.2017 / 17:58

0 answers