MongoError:复合索引的E11000重复键错误集合(不是唯一的)

时间:2018-10-12 05:53:20

标签: node.js mongodb on-duplicate-key compound-index

  1. Nodejs mongodb模块:

**db.collection('pci')    
    .insertOne({bl: 'register',     
    product: 'hlr',     
    branch: 'master',    
    buildid: 'HLRYL190027z'}, (err,pciResult) => {....});** 

  1. 错误详细信息:
    MongoError:insertDocument ::由:: 11000 E11000引起的重复键错误索引:pipeline.pci。$ bl_1_product_1_branch_1_buildid_1 dup键:{:“ registers”,:“ hlr”,:“ master”,:“ HLRYL1900271”}
    在Function.MongoError.create(/data/falcon/producer/node_modules/mongodb-core/lib/error.js:31:11)
  2. 图片集中的文档

{"_id":"5bbcf2f12f717e8492c3e873",    
    "product":"hlr",     
    "rollback":"NO",    
    "buildresult":"PASS",    
    "buildstart":1539108375,    
    "buildid":"HLRYL1900271",    
    "bl":"registers",    
    "branch":"master"}

  1. 图片收藏的索引(没有唯一性)

[
	{
		"v" : 1,
		"key" : {
			"_id" : 1
		},
		"name" : "_id_",
		"ns" : "pipeline.pci"
	},
	{
		"v" : 1,
		"key" : {
			"buildstart" : 1
		},
		"name" : "buildstart_1",
		"ns" : "pipeline.pci"
	},
	{
		"v" : 1,
		"key" : {
			"product" : 1,
			"branch" : 1,
			"type" : 1,
			"buildend" : -1
		},
		"name" : "product_1_branch_1_type_1_buildend_-1",
		"ns" : "pipeline.pci"
	},
	{
		"v" : 1,
		"key" : {
			"buildid" : -1
		},
		"name" : "buildid_-1",
		"ns" : "pipeline.pci"
	},
	{
		"v" : 1,
		"key" : {
			"buildend" : -1
		},
		"name" : "buildend_-1",
		"ns" : "pipeline.pci"
	},
	{
		"v" : 1,
		"key" : {
			"bl" : 1,
			"product" : 1,
			"branch" : 1,
			"buildid" : -1
		},
		"name" : "bl_1_product_1_branch_1_buildid_-1",
		"ns" : "pipeline.pci"
	},
	{
		"v" : 1,
		"key" : {
			"promotion_tags" : -1
		},
		"name" : "promotion_tags_-1",
		"ns" : "pipeline.pci"
	},
	{
		"v" : 1,
		"key" : {
			"product" : 1,
			"branch" : 1,
			"type" : 1,
			"buildstart" : -1
		},
		"name" : "product_1_branch_1_type_1_buildstart_-1",
		"ns" : "pipeline.pci"
	}
]

5.环境
mongodb nodejs模块:“〜2.1.21”,
mongodb:MongoDB外壳程序版本:2.6.11
6.分析
我搜索了很多有关此问题的资源,
但我不知道为什么会引发此错误。
也许并发?但是nodejs是单线程的,因此我尚未为此操作创建新的子进程。
Mongodb的问题? 索引问题?

0 个答案:

没有答案