MongoError:修饰符不允许使用字段名称复制

时间:2014-04-16 20:48:22

标签: javascript node.js mongodb mongoose

注意:据我所知,我没有做推送式游戏。

我有这个第一次工作正常,但如果客户端调用此方法两次而不刷新页面中间调用,我将在标题中收到错误。

scenarios.findOne({'_id':partialUpdate._id},function(err,back){

            if(back){
                for(var p in partialUpdate){
                    if(partialUpdate.hasOwnProperty(p)){
                        back[p] = partialUpdate[p];
                    }
                }
                back.save(function(err,product,numberAffected){...

刷新阻止此错误发生的页面是什么意思? 如何判断我复制的字段名称,以便我可以停止此错误?

这里是服务器输出的副本,其中包含第一和第二组已发送数据(partialData),与其合并的服务器数据(back)以及保存的数据( product)和错误消息

http://pastebin.com/izbkZV1h

第一组发送对象:

{ sortOrder: 0,
  title: 'sdfsdf',
  description: '',
  contentType: 'false',
  _id: '534ec5c98c4bf1be305fee1c',
  __v: 8,
  groupSharing: [],
  sharingWith: [],
  isPublic: false,
  content: false,
  attributes: [],
  metrics:
   [ { type: 'viewCount',
       value: '1',
       metric: 'Viewed',
       _id: '534ec5c98c4bf1be305fee1e',
       createDate: '2014-04-16T18:02:49.454Z' },
     { type: 'playCount',
       value: '1',
       metric: 'Played',
       _id: '534ec5c98c4bf1be305fee1d',
       createDate: '2014-04-16T18:02:49.453Z' } ],
  bundleId: [],
  video:
   [ { videoLocation: 'rtmp://xxxxxxxxxxxxxxxxxxx.cloudfront.net/cfx/st/vid_51323386'
,
       thumbnailLocation: 'https://xxxxxxxxxxxxxxxxxxx.cloudfront.net/thumb_51323386.
png',
       _id: '534ec5c98c4bf1be305fee20',
       createDate: '2014-04-16T18:02:49.457Z',
       format: 'FLV' } ],
  display: true,
  active: true,
  createDate: '2014-04-16T18:02:49.000Z',
  revision: 1,
  scripts:
   [ { _id: '534ec5c98c4bf1be305fee1f',
       display: true,
       active: true,
       createDate: '2014-04-16T18:02:49.454Z',
       keyPoints: [],
       body: [Object],
       subject: [] } ],
  presentation:
   [ { pageLocation: null,
       _id: '534ec5c98c4bf1be305fee21',
       display: true,
       active: true,
       syncManifest: [],
       pageNumber: [Object] } ],
  subcategoryId: [ '53236dff2ab8b9182716f34d' ],
  categoryId: [ '532369bb2ab8b9182716f33d' ],
  authorId: [ '532c9a146ce0682319cebbf9' ] }

服务器上的对象应该覆盖:

 { sortOrder: 0,
  title: 'sdfsdf',
  description: '',
  contentType: 'false',
  _id: 534ec5c98c4bf1be305fee1c,
  __v: 8,
  groupSharing: [],
  sharingWith: [],
  isPublic: false,
  content: false,
  attributes: [],
  metrics:
   [ { type: 'viewCount',
       value: '1',
       metric: 'Viewed',
       _id: 534ec5c98c4bf1be305fee1e,
       createDate: Wed Apr 16 2014 12:02:49 GMT-0600 (Mountain Daylight Time) },

     { type: 'playCount',
       value: '1',
       metric: 'Played',
       _id: 534ec5c98c4bf1be305fee1d,
       createDate: Wed Apr 16 2014 12:02:49 GMT-0600 (Mountain Daylight Time) }
],
  bundleId: [],
  video:
   [ { videoLocation: 'rtmp://xxxxxxxxxxxxxxxxxxx.cloudfront.net/cfx/st/vid_51323386'
,
       thumbnailLocation: 'https://xxxxxxxxxxxxxxxxxxxxcloudfront.net/thumb_51323386.
png',
       _id: 534ec5c98c4bf1be305fee20,
       createDate: Wed Apr 16 2014 12:02:49 GMT-0600 (Mountain Daylight Time),
       format: 'FLV' } ],
  display: true,
  active: true,
  createDate: Wed Apr 16 2014 12:02:49 GMT-0600 (Mountain Daylight Time),
  revision: 1,
  scripts:
   [ { _id: 534ec5c98c4bf1be305fee1f,
       display: true,
       active: true,
       createDate: Wed Apr 16 2014 12:02:49 GMT-0600 (Mountain Daylight Time),
       keyPoints: [],
       body: [Object],
       subject: [] } ],
  presentation:
   [ { pageLocation: null,
       _id: 534ec5c98c4bf1be305fee21,
       display: true,
       active: true,
       syncManifest: [],
       pageNumber: [Object] } ],
  subcategoryId: [ 53236d392ab8b9182716f341 ],
  categoryId: [ 532368bc2ab8b9182716f339 ],
  authorId: [ 532c9a146ce0682319cebbf9 ] }

结果对象:

    { sortOrder: 0,
  title: 'sdfsdf',
  description: '',
  contentType: 'false',
  _id: 534ec5c98c4bf1be305fee1c,
  __v: 9,
  groupSharing: [],
  sharingWith: [],
  isPublic: false,
  content: false,
  attributes: [],
  metrics:
   [ { type: 'viewCount',
       value: '1',
       metric: 'Viewed',
       _id: 534ec5c98c4bf1be305fee1e,
       createDate: Wed Apr 16 2014 12:02:49 GMT-0600 (Mountain Daylight Time) },

     { type: 'playCount',
       value: '1',
       metric: 'Played',
       _id: 534ec5c98c4bf1be305fee1d,
       createDate: Wed Apr 16 2014 12:02:49 GMT-0600 (Mountain Daylight Time) }
],
  bundleId: [],
  video:
   [ { videoLocation: 'rtmp://xxxxxxxxxxxxxxxxxxx.cloudfront.net/cfx/st/vid_51323386'
,
       thumbnailLocation: 'https://xxxxxxxxxxxxxxxxxxx.cloudfront.net/thumb_51323386.
png',
       _id: 534ec5c98c4bf1be305fee20,
       createDate: Wed Apr 16 2014 12:02:49 GMT-0600 (Mountain Daylight Time),
       format: 'FLV' } ],
  display: true,
  active: true,
  createDate: Wed Apr 16 2014 12:02:49 GMT-0600 (Mountain Daylight Time),
  revision: 1,
  scripts:
   [ { _id: 534ec5c98c4bf1be305fee1f,
       display: true,
       active: true,
       createDate: Wed Apr 16 2014 12:02:49 GMT-0600 (Mountain Daylight Time),
       keyPoints: [],
       body: [Object],
       subject: [] } ],
  presentation:
   [ { pageLocation: null,
       _id: 534ec5c98c4bf1be305fee21,
       display: true,
       active: true,
       syncManifest: [],
       pageNumber: [Object] } ],
  subcategoryId: [ 53236dff2ab8b9182716f34d ],
  categoryId: [ 532369bb2ab8b9182716f33d ],
  authorId: [ 532c9a146ce0682319cebbf9 ] }

我注意到的一个区别是,我发送了一个字符串数组,而不是像Wed Apr 16 2014 12:02:49 GMT-0600 (Mountain Daylight Time)这样的日期,而不是发送一个ObjectID数组,我发送它2014-04-16T18:02:49.454Z。那会有关系吗?

1 个答案:

答案 0 :(得分:2)

修正了它:

https://github.com/LearnBoost/mongoose/issues/1933

我明确地保存了__v属性,这是一个禁忌。

在我的循环中,我只是检查p是否等于__v,如果是,我会忽略它。没问题。