Use the same Schema inside a daughter key with Mongoose

Asked

Viewed 139 times

1

I’m working with Nodejs, Mongodb and Mongoose where I’m creating a system of access permissions that work with infinite sublevels. 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 in trying to create this sublevel structure, my code is making a mistake by saying I can’t use it as a reference...

How can I create an infinite sublevel structure to work with these permissions?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.