MongoDB/Mongoose unique constraint on Date field
问题 I have declared a unique index on a schema like so: var stateChangeEventSchema = mongoose.Schema({ client_timestamp: { type: Date, required: true, unique: true }, state: { type: String, required: true } }) And am able to insert a document with identical timestamps. I would expect a constraint violation. I thought it might be because it's on an embedded document, but I tried on a regular document, and it still allows it. What am I missing? Edit : I found the issue. I was failing to create