const mongoose = require('mongoose').set('debug', false)
const Schema = mongoose.Schema;

mongoose.Promise = global.Promise;
mongoose.level = "F";

const tools = require('../tools/general');
const { ObjectID } = require('mongodb');

// Resolving error Unknown modifier: $pushAll
mongoose.plugin(schema => {
  schema.options.usePushEach = true
});

const CfgServerSchema = new Schema({
  chiave: {
    type: String,
    trim: true,
    minlength: 1,
  },
  idapp: {
    type: String,
  },
  userId: {
    type: String,
  },
  valore: {
    type: String,
  },
});

CfgServerSchema.statics.DuplicateAllRecords = async function (idapporig, idappdest) {

  return await tools.DuplicateAllRecords(this, idapporig, idappdest);

};

CfgServerSchema.statics.findAllIdApp = async function(idapp) {
  const myfind = { idapp };

  return await CfgServer.find(myfind).lean();
};

const CfgServer = mongoose.model('CfgServer', CfgServerSchema);

module.exports = {CfgServer};

