code: def get_field_info(model):
      
      # Deal with the primary key.
      if issubclass(model, mongoengine.EmbeddedDocument):
          pk = None
      else:
          pk = model._fields[model._meta['id_field']]
  
      # Deal with regular fields.
      fields = OrderedDict()
  
      # Deal with forward relationships.
      # Pass forward relations since there is no relations on mongodb
      references = OrderedDict()
  
      embedded = OrderedDict()
  
      def add_field(name, field):
          if isinstance(field, REFERENCING_FIELD_TYPES):
              references[name] = get_relation_info(field)
          elif isinstance(field, EMBEDDING_FIELD_TYPES):
              embedded[name] = get_relation_info(field)
          elif isinstance(field, COMPOUND_FIELD_TYPES):
              fields[name] = field
              if field.field:
                  add_field(name + '.child', field.field)
          elif field is pk:
              return
          else:
              fields[name] = field
  
      for field_name in model._fields_ordered:
          add_field(field_name, model._fields[field_name])
  
      # Shortcut that merges both regular fields and the pk,
      # for simplifying regular field lookup.
      fields_and_pk = OrderedDict()
      fields_and_pk['pk'] = pk
      fields_and_pk[getattr(pk, 'name', 'pk')] = pk
      fields_and_pk.update(fields)
  
      return FieldInfo(pk,
                       fields,
                       references,
                       fields_and_pk,
                       embedded)
docs: Given a model class, returns a `FieldInfo` instance, which is a
      `namedtuple`, containing metadata about the various field types on the model
      including information about their relationships.