Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs Breeze Mongo角自动生成键错误_Angularjs_Mongodb_Breeze - Fatal编程技术网

Angularjs Breeze Mongo角自动生成键错误

Angularjs Breeze Mongo角自动生成键错误,angularjs,mongodb,breeze,Angularjs,Mongodb,Breeze,我用微风吹角和MongoDB 我包括了所有必要的服务和脚本,以确保breeze与angular和MongoDB一起工作 但是,当我尝试保存更改时,服务器上出现以下错误: ObjectIds and Guids are the only autoGenerated key types that Breeze currently supports, not: undefined 此错误发生在mongobreeze模块的mongoSaveHandler.js文件中: var keyDataType

我用微风吹角和MongoDB

我包括了所有必要的服务和脚本,以确保breeze与angular和MongoDB一起工作

但是,当我尝试保存更改时,服务器上出现以下错误:

ObjectIds and Guids are the only autoGenerated key types that Breeze currently supports, not: undefined 
此错误发生在mongobreeze模块的mongoSaveHandler.js文件中:

var keyDataType = entityType.keyDataType;
            if (keyDataType === "Guid") {
                e._id = createGuid();
            } else if (keyDataType == "MongoObjectId") {
                // instead of omitting the _id and having mongo update it, we want to set it ourselves so that we can do
                // fk fixup before going async
                e._id = new ObjectID();
            } else {
                that._raiseError(new Error("ObjectIds and Guids are the only autoGenerated key types that Breeze currently supports, not: " + keyDataType));
                return;
            }
我确保我的对象的id是mongo id:

function addVisit() {
    addType({
        name: 'Visit',
        dataProperties: {
            id: { type: DT.MongoObjectId },
            pain: { type: ID },
            paper: {type: ID},
            consistency: {type: ID}
        }
    });
}
但实际上,当我记录entityType对象时,它没有属性keyDataType

只要我消除错误,我就能让一切正常工作。然后我插入的对象在MongoDB中看起来像这样:

{ id: 5350d4e704a02e1f04000000,
pain: 50,
consistency: 50,
date: Fri Apr 18 2014 08:31:51 GMT+0100 (WEST),
_id: 5350d4e7101b04a9560e660a },
意思是他们有两个身份证

当我尝试查询数据库时,我得到了一个很好的响应:

[
  {
    "id": "535052f504a02e79c6000000",
    "pain": 50,
    "consistency": 50,
    "_id": "535052f6f672174a4dffffd4"
  },
  {
    "id": "5350d1bb04a02e4e56000000",
    "pain": 50,
    "consistency": 50,
    "date": "2014-04-18T07:18:19.616Z",
    "_id": "5350d1bb101b04a9560e6606"
  },
  {
    "id": "5350d2c104a02e595c000000",
    "pain": 50,
    "consistency": 50,
    "date": "2014-04-18T07:22:41.696Z",
    "_id": "5350d2c1101b04a9560e6607"
  },
]
但不知何故,Breeze无法正确导入此项,我得到了一个循环依赖项


这可能与双ID有关吗?

您从哪里获得DT.MongoObjectId的?在breeze文档中未作为受支持的数据类型列出,因此它将作为类型返回undefined。如果您正确地生成了Id,为什么不使用不可变的字符串呢

id : { type: DT.String }

尝试设置一个命名约定,将breeze的
“id”
字段转换为mongo的
“\u id”
,反之亦然。它将消除双ID
以下是客户端的代码:

var convention = new breeze.NamingConvention({
    serverPropertyNameToClient: function (serverPropertyName) {
        switch (serverPropertyName) {
            case '_id':
                return 'id';
            default :
                return serverPropertyName;
        }
    },
    clientPropertyNameToServer: function (clientPropertyName) {
        switch (clientPropertyName) {
            case 'id':
                return '_id';
            default:
                return clientPropertyName;
        }
    }
});

convention.setAsDefault();

附加图像是好的。breeze中的每个实体都有实体方面。EntityAspect反过来具有对其实体的反向引用。Breeze使用循环引用非常有效。看看EntityAspect文档,我看到了,但是当我尝试使用angular显示它们时,我得到了一个插值错误,因为循环依赖关系angular在绑定时无法处理具有循环引用的对象。您应该从breeze实体向另一个javascript对象进行投影,而不使用angular to Working的循环引用。breeze.dataservice.mongo.js对该对象进行了修补,但它也不适用于Guid。