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 searchSchema = new Schema({
  idapp: {
    type: String,
  },
  userId: {
    type: String,
  },
  text: {
    type: String,
  },
});

searchSchema.statics.findAllByUserIdAndIdApp = function (userId, idapp, sall) {
  const Search = this;

  let myfind = {};
  if (sall === '1')
    myfind = { idapp };
  else
    myfind = { userId, idapp };

  return Search.find(myfind, (err, arrsearch) => {
    return arrsearch
  });
};


const Search = mongoose.model('Search', searchSchema);

module.exports = { Search };
