0

I have set up the following model in MongoDB using MongoEngine.

class Category(Document):

    normed_name = StringField(),
    name = StringField(),
    path = StringField(),

The model was different initially and I did import some documents, but I have deleted all old databases and changed the model to the above.

When I then run the following python script:

import model
from mongoengine import connect

uri = 'mongodb://<user>:<pass>@<me>.mlab.com:<port>/cost_database'

connect('cost_database', host = uri)

test = model.Category()
test.name = 'test'
print(test.name)
test.save(validate=False)

The script outputs,

test

But in the database the following file is created:

{
    "_id": {
        "$oid": "5a61e64dc645177b50d0d656"
    }
} 

Any idea on why name wasn't saved?

Domronic
  • 149
  • 1
  • 1
  • 11

1 Answers1

4

My error was adding commas after the definitions of the fields.

class Category(Document):

    normed_name = StringField()
    name = StringField()
    path = StringField()

the above solved the issue.

I'll never get the time it took me to realise this back unfortunately. :(

Domronic
  • 149
  • 1
  • 1
  • 11