JKHeadley / appy-backend

A user system to bootstrap your app.
https://appyapp.io
MIT License
108 stars 30 forks source link

Adding a new model object #17

Closed kpfromer closed 7 years ago

kpfromer commented 7 years ago

I am having troubles adding a new model object to the appy server. I am creating a new simple model called models/task.model.js

'use strict';

module.exports = function (mongoose) {
    var modelName = "task";
    var Types = mongoose.Schema.Types;
    var Schema = new mongoose.Schema({
        description: {
            type: Types.String,
            required: true
        },
        complete: {
            type: Types.Boolean,
            required: true
        }
    }, { collection: modelName });

    Schema.statics = {
        collectionName:modelName,
        routeOptions: {

        }
    };

    return Schema;
};

And I then authenticate myself using the superadmin account and create a task like by posting the following

{
"description": "hello",
"complete": false
}

And I get this error

{
    "statusCode": 409,
    "error": "Conflict",
    "message": "There was a duplicate key error."
}

What am I doing wrong?

Thanks, Kyle Pfromer

JKHeadley commented 7 years ago

@kpfromer it looks like you have everything set up right. I tested your code and I'm not getting any errors. That particular error is caused by a unique index error with mongodb. Did you by chance add a unique index to one of your model properties earlier?

kpfromer commented 7 years ago

Thanks for the fast response, I dropped the database and it now works. It must have been an issue with changing scope settings. Thanks!