-
-
Notifications
You must be signed in to change notification settings - Fork 12
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
Increment key based on another field #4
Comments
with this plugin currently not possible |
Any update on this? |
like it was said earlier in the comments, it is currently not possible. if you want it yourself, either implement it and send a PR or better explain what is necessary / wanted. to summarize (on my understanding), you would need a external (like |
I just happen to come across this old issue, which I happened to have solved myself a few years back (if I'm interpreting the problem correctly). If the issue is that you want a separate counter in the same collection based on the value of another field, check out the change I added to a (very) old version of auto-increment, based on the original mongoose-auto-increment: v0.9.0...MxBlu:auto-increment:master Taking a cursory glance at the latest version of this repo, my changes should still work. I'm not interested in maintaining my old repo but anyone is free to take these changes for themslves. |
@MxBlu if i understand your code correctly, that change will allow you to have a different counter document depending on the value of another field, ie: // a document for shop "a"
{
for_shop: "a",
}
// would use tracker
{
field: "_id",
modelName: "SomeModel",
count: 10,
reference_values: {
for_shop: "a"
}
}
// where as a document for shop "b"
{
for_shop: "b"
}
// would use a different tracker document
{
field: "_id",
modelName: "SomeModel",
count: 5,
reference_values: {
for_shop: "b"
}
}
// for the same model if it this is wanted, it could easily be added (thanks to your code), though i am still not fully sure if this is what OP wanted out of this. |
Exactly yea, and agreed. I'm just leaving this here for anyone that stumbles upon it in the future, since the issue description happened to be how I described my problem too. |
Let's say we have Incremented Value(ref) in the document which need to be incremented based on another field(shopId)
What kind of approach can we have? ( the two properties are compound index)
The text was updated successfully, but these errors were encountered: