mongoengine.errors.FieldDoesNotExist:文档“WorkflowExecutions”中不存在字段“{'__v'}”

问题描述 投票:0回答:1

我正在使用 python-flask 和 mongodb。一切正常,突然我收到以下错误

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

我在nodets应用程序中共享此表,我也在nodets中为此表创建了模型。两者都有相同的字段。我什至重新启动了代码库,系统删除了表,但仍然遇到同样的问题。

返回错误的代码

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

烧瓶模型

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 模型

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;
python node.js mongodb flask mongoengine
1个回答
0
投票

绕过由nodejs模型创建的字段__v。在类

WorkflowExecutions
添加元
strict
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}
© www.soinside.com 2019 - 2024. All rights reserved.