Closed toxicafunk closed 5 years ago
Hi @toxicafunk,
Looking at the description of what upsert does:
// Upsert finds a single document matching the provided selector document
// and modifies it according to the update document. If no document matching
// the selector is found, the update document is applied to the selector
// document and the result is inserted in the collection.
// If the session is in safe mode (see SetSafe) details of the executed
// operation are returned in info, or an error of type *LastError when
// some problem is detected.
The selector you're using in your upsert test doesn't use the eventid, so the behaviour you're experiencing is expected. You can have a look at some of the upsert examples in the tests for understanding the usage.
Thanks, Esther
Thanks @eminano,
Can confirm I messed up the selector and it actually works correctly. Thanks for your time.
What version of MongoDB are you using (
mongod --version
)?What version of Go are you using (
go version
)?What operating system and processor architecture are you using (
go env
)?What did you do?
Given the following collection and index
When trying to insert 2 documents with same profileid, createdat and sessionid BUT different eventid, eventid is ignored from the index query so instead of creating a new document the previous one s updated. See attached test for the struct and code.
Debugging mongo I can see that eventid is being treated as an Array:
Insert
andBulk
work as expected as can be determined from the test.mongodb_test.txt