ListField

34 views
Skip to first unread message

Burhan GÖKSEL

unread,
Jul 26, 2022, 8:26:19 AM7/26/22
to MongoEngine Users
Greetings To You All,

The mongoengine we use for work gives list fields not type error in the documents I create.
For example:

Code:
class Y(EmbeddedDocument):
id = StringField()
name = StringField()

class X(Document):
author = StringField()
y = ListField(EmbeddedDocumentField(Y))

query :
{x{
  id,
  author,
  y
}}

error message :

      "message": "Cannot query field 'y' on type 'XOutput'.",


Thank you very much in advance to those who help.

Priya Lorha

unread,
Jul 26, 2022, 11:40:05 AM7/26/22
to mongoeng...@googlegroups.com
Why don't you use embedded document list field

--
You received this message because you are subscribed to the Google Groups "MongoEngine Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongoengine-us...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongoengine-users/2e4d3afb-db3a-4372-8e6f-d1db5ab6d24an%40googlegroups.com.

Burhan GÖKSEL

unread,
Jul 27, 2022, 2:19:52 AM7/27/22
to mongoeng...@googlegroups.com
y = ListField(EmbeddedDocumentField(Y)) to y = ListField(DictField()) solved problem. But read operation is running, but the create is not.

Query =
mutation{
  createX(
    artifact:{
  name :"student",
    y: [{name:"burhan"]
    }
  ){
    x{
      id
    }
  }
}

my document =
class X(Document):
author = StringField()
y = ListField(DictField())

Error messages =
"message": "ValidationError (Artifact:None) (Only dictionaries may be used in a DictField: ['y'])",

Priya Lorha <priya...@gmail.com>, 26 Tem 2022 Sal, 18:40 tarihinde şunu yazdı:

Clara Daia

unread,
Jul 27, 2022, 1:28:48 PM7/27/22
to mongoeng...@googlegroups.com
You may have a typo in your mutation:
     y: [{name:"burhan"]
    }
Should be
     y: [{name:"burhan"}]
    }
Nevertheless, Pryia's suggestion of using an embedded doc field seems correct and is probably better in the long run if you want to have validations on the list items.

Burhan GÖKSEL

unread,
Jul 27, 2022, 4:52:07 PM7/27/22
to mongoeng...@googlegroups.com
Thanks for support.  The problem was in the query I sent :).

Reply all
Reply to author
Forward
0 new messages