class Document(db.Document):
title = db.StringField(required=True,)
class Collection(db.Document):
# Some fields
# ...
documents = db.ListField(db.ReferenceField(Document))
But when I make an AJAX call to the API to add a document to the collection, I obtain the error {"field-errors": {"documents": {"0": "A ReferenceField only accepts DBRef, ObjectId or documents", "1": "A ReferenceField only accepts DBRef, ObjectId or documents"}}}.
Raw data: {"title":"qsdhv qs 456 Js","documents":["59383fbeb15ab314ca83a553","59385172b15ab320806ed814"],"id":"593719c2b15ab34148e85c59"}
If I use a list of ObjectIdFields instead of a ReferenceFields for models.Collection.documents, it works. But if I add a List(MongoReferenceDocument) constraint in the schema of CollectionRessource, it does not work anymore.
I only have the error with the PUT method. When I fill the documents attribute in a POST request, it works.
Hi!
I have the following models:
Then I defined my API the simplest way:
After filling the db with
mongoengine
, I requesthttp://127.0.0.1:5000/collections/593719c2b15ab34148e85c59/
:But when I make an AJAX call to the API to add a document to the collection, I obtain the error
{"field-errors": {"documents": {"0": "A ReferenceField only accepts DBRef, ObjectId or documents", "1": "A ReferenceField only accepts DBRef, ObjectId or documents"}}}
.http://127.0.0.1:5000/collections/593719c2b15ab34148e85c59/
PUT
{"title":"qsdhv qs 456 Js","documents":["59383fbeb15ab314ca83a553","59385172b15ab320806ed814"],"id":"593719c2b15ab34148e85c59"}
If I use a list of
ObjectIdField
s instead of aReferenceField
s formodels.Collection.documents
, it works. But if I add aList(MongoReferenceDocument)
constraint in the schema ofCollectionRessource
, it does not work anymore.I only have the error with the
PUT
method. When I fill thedocuments
attribute in aPOST
request, it works.Thanks