--You received this message because you are subscribed to the Google Groups "mongodb-user"To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/CAMT20g8vUiLfaSTMA6dS%2BBk8rmGt4vat_D0DEXSZ6A4%2BgRtyow%40mail.gmail.com.
group.
For other MongoDB technical support options, see: http://www.mongodb.org/about/support/.
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at http://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/CAOe6dJAGM0jTght-HQpMdxF-gEKVvdxK155dzTYs1StD3w2EYw%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/CAMT20g-JGfu9EDHz3b-9pNGsrusWwuFy8hxdfX4wzzVX_MH00g%40mail.gmail.com.
This might be a newb question, but why would you also need to extra logic in your query for MongoDB to figure out for every increment update, when it isn't really needed for most of those updates? I mean, the insert would most likely be much rarer than the update, isn't it? Covering both situations in one query wouldn't gain you much in network bandwidth, CPU usage or programming simplicity, would it?
Scott
--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
For other MongoDB technical support options, see: http://www.mongodb.org/about/support/.
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at http://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/11293ece-bcc3-4b58-9036-06324f797eda%40googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
For other MongoDB technical support options, see: http://www.mongodb.org/about/support/.
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at http://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/11f04963-f8dd-4003-b2c7-37df7a53a47c%40googlegroups.com.
This might be a newb question, but why would you also need to extra logic in your query for MongoDB to figure out for every increment update, when it isn't really needed for most of those updates? I mean, the insert would most likely be much rarer than the update, isn't it? Covering both situations in one query wouldn't gain you much in network bandwidth, CPU usage or programming simplicity, would it?
All I can suggest then, is to vote for the suggestion in Jira Glenn pointed to. https://jira.mongodb.org/browse/SERVER-6566
And I have to agree too. Doesn't seem logical to have a setOnInsert parameter and it not work on an insert, no matter what other parameters and fields are there. It should just basically override any duplicated field name so that the one parameter can be set on insert and the other during an update.
--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
For other MongoDB technical support options, see: http://www.mongodb.org/about/support/.
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at http://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/91175343-c3d8-4ecd-b809-e75b0c7c2f7c%40googlegroups.com.
Hold on, this isn't correct. An update has some fields that get set. If it's an upsert then *in addition* some other fields will be set on insert.
It's not either or.
This of set on insert functionality something that allows you to initialize certain fields when you create the record that you don't want to touch when you update it. Whether or not you're querying on _id or unique field is not relevant.
I'm updating a record and I always want to set "lastUpdated" field to current time on update. In addition, when it's an upsert, I also want to set "createdOn" field to current time, but never touch it after. This is exactly where you would always do {$set:{lastUpdated:$currentDate},$setOnInsert:{createdAt:$currentDate}Asya
It still doesn't make sense to me though, if the "find" is querying on a unique field (which is recommended and was used in Albert's example), how could there still be a concurrency issue for inserts?
And the use case in this thread isn't about a concurrency issue with updating directly, because there is nothing to hamper a race condition on the update in Albert's use case. That is actually the main concern of the Jira suggestion you referred to, right? Concurrency during updates? Basically pushing conditional logic more into Mongo, so things can be checked and/ or updated in one shot?
So, that all being said, I do agree, there will be a possible race condition, if a unique field isn't being used in the "find" query for findAndModify with upsert set to true. For this reason, a unique field to query on is recommended. In other words, it isn't the use of duplicate parameters in Albert's situation, which would help solve any concurrency concerns for the insert. It is what is being found and how it is being found (or not). Because, even if you add the ability to have the same parameters as Albert suggests, without the unique index being the determining factor to insert on, you're back to a possible race condition. I would think.So theoretically, the Jira suggestion could be extended to basically add that inserts could be carried out according to more conditions within the findAndModify command with upsert set to true, so a unique index isn't always needed?
....setOnInsert. You lost me there with "multiple-consecutive-updates". That is exactly my (and I believe Albert's) point. The setOnInsert has absolutely nothing to do with updates. The way I understand how it could work, if Mongo determines it is inserting, it sets fields according to what is behind setOnInsert. If Mongo determines it is updating, then any updating parameters are followed and all the setOnInsert stuff is ignored. In other words, findAndModify should simply logically separate what is done on an insert and what is done on an update.
--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
For other MongoDB technical support options, see: http://www.mongodb.org/about/support/.
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at http://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/CAMT20g8z3M1Mrei0N_5z4SMuk_%3D82ZDm-M_w4j3D%2BY75q4XhLQ%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/CAOe6dJDt7t15Tg3kQZ3w6Rf1%3DJQ53wwWf2aA18YoDzyadCPNdw%40mail.gmail.com.
Since the "update" part of the update is always performed, I just don't see how I can parse your scenario.
There is no way to have something happen *only* on an update and *not* on an upsert.
But let's make it simpler, let's say we're talking about an update of existing document only. Can you see how it wouldn't make sense to say
update({},{$set:{a:1},$inc:{a:1}})
right?
Asya
--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
For other MongoDB technical support options, see: http://www.mongodb.org/about/support/.
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at http://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/d37180c5-870b-4fbc-b744-093a5544154d%40googlegroups.com.
Since the "update" part of the update is always performed, I just don't see how I can parse your scenario.
--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
For other MongoDB technical support options, see: http://www.mongodb.org/about/support/.
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at http://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/93229885-bd47-424b-8dde-14920ac94ca3%40googlegroups.com.