[SERVER-82975] Timeseries insert misreports "n" field when errors are present Created: 08/Nov/23  Updated: 09/Nov/23  Resolved: 08/Nov/23

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Vishnu Kaushik Assignee: Backlog - Storage Execution Team
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-79787 Ordered timeseries inserts may return... Closed
Assigned Teams:
Storage Execution
Operating System: ALL
Participants:

 Description   

Create a timeseries collection:

> db.runCommand({create: "myts", timeseries: {timeField: "t", metaField: "sensor"}})
{
	"ok" : 1,
	...
}

Try to insert an invalid doc to it. Notice that {"n" : 1}, though nothing was inserted.

> db.runCommand({insert: "myts", documents: [{"metadata": { "sensor": 2},  "u": ISODate("2021-05-18T00:00:00.000Z"), "temp": 12}]})
{
	"n" : 1,
	"writeErrors" : [
		{
			"index" : 0,
			"code" : 2,
			"errmsg" : "'t' must be present and contain a valid BSON UTC datetime value"
		}
	],
	"ok" : 1,
	...
}
 
> db.myts.find().itcount()
0

For a non-timeseries collection, on a write error (say DuplicateKeyError) the correct n is returned:

> db.runCommand({insert: "basic4", documents: [{_id: 1}]})
{
	"n" : 0,
	...
	"writeErrors" : [
		{
			"index" : 0,
			"code" : 11000,
			"errmsg" : "E11000 duplicate key error collection: test.basic4 index: _id_ dup key: { _id: 1.0 } found value: RecordId(3)",
			"keyPattern" : {
				"_id" : 1
			},
			"keyValue" : {
				"_id" : 1
			},
			"foundValue" : NumberLong(3),
			"duplicateRid" : NumberLong(3)
		}
	],
	"ok" : 1,
        ...
}



 Comments   
Comment by Vishnu Kaushik [ 08/Nov/23 ]

Good catch gregory.noma@mongodb.com. I'll close this.

Comment by Gregory Noma [ 08/Nov/23 ]

This may be a duplicate of SERVER-79787

Generated at Thu Feb 08 06:50:54 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.