Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing write concern during the save call #2494

Closed
FelikZ opened this issue Nov 27, 2014 · 6 comments · Fixed by #2516
Closed

Passing write concern during the save call #2494

FelikZ opened this issue Nov 27, 2014 · 6 comments · Fixed by #2516
Milestone

Comments

@FelikZ
Copy link

FelikZ commented Nov 27, 2014

How to do that?

For now I am using:

MongooseModel.collection.insert({ "some": "data" }, { writeConcern: 'journaled' }, callback);

But I want to do it in that or similar way:

var m = new MongooseModel({ "some": "data" });
m.save({ writeConcern: 'journaled' }, callback);

I didn't find anything about writeConcern in mongoose.

@yads
Copy link

yads commented Nov 27, 2014

Check out the safe option http://mongoosejs.com/docs/guide.html

@FelikZ
Copy link
Author

FelikZ commented Nov 27, 2014

@yads yes, I already checked in this. But I want dynamically change behavior of the application. The safe option is required to set once, not per query.

@yads
Copy link

yads commented Nov 27, 2014

It can be set per query too, via the options object:

http://mongoosejs.com/docs/api.html#model_Model.update
http://mongoosejs.com/docs/api.html#query_Query-update

On Thu, Nov 27, 2014 at 2:04 PM, Alexey Shevchenko <notifications@github.com

wrote:

@yads https://github.com/yads yes, I already checked in this. But I
want dynamically change behavior of the application. The safe option is
required to set once, not per query.


Reply to this email directly or view it on GitHub
#2494 (comment)
.

-Vadim Kazakov

@FelikZ
Copy link
Author

FelikZ commented Nov 28, 2014

@yads thanks for this, I didn't know about safe updates availability. But this still doesn't solve the case, when I need to make safe or not safe inserts by save function, depending on application behavior.

@yads
Copy link

yads commented Nov 28, 2014

That's definitely a limitation. It's surprising that there is a way to pass
options to updates, but not inserts. From what I've seen of the code it's
because Model.create allows you to insert multiple documents and hence
they can't tell if you're inserting 2 documents or supplying a document and
an options object. This may be tricky to update without some serious
modifications to how model creation works. I'd love if one of the
maintainers chimed in.

On Fri, Nov 28, 2014 at 2:34 AM, Alexey Shevchenko <notifications@github.com

wrote:

@yads https://github.com/yads thanks for this, I didn't know about safe
updates availability. But this still doesn't solve the case, when I
need to make safe or not safe inserts, depending on application
behavior.


Reply to this email directly or view it on GitHub
#2494 (comment)
.

-Vadim Kazakov

@vkarpov15
Copy link
Collaborator

Unfortunately this is currently impossible. Definitely should be added though.

@vkarpov15 vkarpov15 added this to the 4.0 milestone Dec 1, 2014
jondavidjohn added a commit to jondavidjohn/mongoose that referenced this issue Dec 5, 2014
@vkarpov15 vkarpov15 modified the milestones: 3.9.6, 4.0 Dec 5, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants