var mongoose = require('mongoose'); const _ = require('lodash'); const tools = require('../tools/general'); mongoose.Promise = global.Promise; mongoose.level = "F"; // Resolving error Unknown modifier: $pushAll mongoose.plugin(schema => { schema.options.usePushEach = true }); mongoose.set('debug', process.env.DEBUG); var TodoSchema = new mongoose.Schema({ userId: { type: String, }, pos: { type: Number, }, category: { type: String, }, descr: { type: String, }, priority: { type: Number, }, completed: { type: Boolean, default: false }, created_at: { type: Date }, modify_at: { type: Date }, completed_at: { type: Date }, expiring_at: { type: Date, }, enableExpiring: { type: Boolean, default: false }, id_prev: { type: String, }, id_next: { type: String, }, progress: { type: Number, }, modified: { type: Boolean, }, }); TodoSchema.methods.toJSON = function () { var todo = this; var todoObject = todo.toObject(); // console.log(todoObject); return _.pick(todoObject, tools.allfieldTodoWithId()); }; TodoSchema.statics.findAllByUserId = function (userId) { var Todo = this; return Todo.find({ 'userId': userId, }); }; TodoSchema.pre('save', function (next) { // var todo = this; // console.log('todo.expiring_at', todo.expiring_at); next(); }); var Todo = mongoose.model('Todos', TodoSchema); module.exports = { Todo };