pythonnode.jsmongodbflaskmongoengine

mongoengine.errors.FieldDoesNotExist: The fields "{'__v'}" do not exist on the document "WorkflowExecutions"


I am working with python-flask and mongodb. Things was working fine suddenly I am getting the below error

mongoengine.errors.FieldDoesNotExist: The fields "{'__v'}" do not exist on the document "WorkflowExecutions"

I am sharing this table in nodets application also I have created the model for this tables in nodets. both are having the same fields. I even restarted the codebase and system deleted the tables but still getting the same issue.

Code which is returning the error

@app.route('/api/task/ping-db', methods=['GET'])
def pingdb():
    execution = WorkflowExecutions.objects(workflow_id ="653224656fd5f59905c58cc6").first()
    return jsonify({"result": execution})

Flask Model

from mongoengine import Document, StringField, ListField, ObjectIdField, DateTimeField, connect
from datetime import datetime
# Define the default MongoDB connection
connect('workflow', host='mongodb://localhost:27017/workflow')

class WorkflowExecutions(Document):
    name = StringField(max_length=255)
    workflow_id = ObjectIdField(required=True, max_length=255)
    nodes = ListField()
    edges = ListField()
    status = StringField(max_length=255)
    createdAt = DateTimeField(default=datetime.utcnow)
    updatedAt = DateTimeField(default=datetime.utcnow)

NodeTs Model

import mongoose, { Schema, Document, ObjectId } from 'mongoose';

interface IExecution extends Document {
  name: string;
  workflow_id: ObjectId;
  nodes: any[]; 
  edges: any[];
  status: string;
}

const execution_schema: Schema = new Schema({
  name: {type: String},
  workflow_id: { type: mongoose.Schema.ObjectId, ref: 'WorkFlow' },
  nodes: [{ type: Schema.Types.Mixed }],
  edges: [{type: Schema.Types.Mixed}], 
  status: {type: String}
},{
  timestamps: true
});

const Execution = mongoose.model<IExecution>('Workflow_execution', execution_schema);

export default Execution;

Solution

  • To bypass field __v which create by nodejs model. In class WorkflowExecutions add meta strict is false.

    class WorkflowExecutions(Document):
        name = StringField(max_length=255)
        workflow_id = ObjectIdField(required=True, max_length=255)
        nodes = ListField()
        edges = ListField()
        status = StringField(max_length=255)
        createdAt = DateTimeField(default=datetime.utcnow)
        updatedAt = DateTimeField(default=datetime.utcnow)
        meta = {"strict": False}