|
Re-filing this as an individual request from SERVER-2362, focusing only on $unshift.
I would like to see $unshift implemented simply as an alias to $push with $position: 0, but without requiring $each, because it doesn't read super intuitively:
Before:
$push: {
|
scores: {
|
$each: [ 50, 60, 70 ],
|
$position: 0
|
}
|
}
|
After:
$unshift: {
|
scores: [ 50, 60, 70 ]
|
}
|
Much cleaner.
Use cases
There are at least four questions on StackOverflow asking how to insert elements at the beginning of an array:
- http://stackoverflow.com/questions/7936019/how-do-i-add-a-value-to-the-top-of-an-array-in-mongodb
- http://stackoverflow.com/questions/13649010/add-values-to-the-beginning-of-an-array-with-mongodb
- http://stackoverflow.com/questions/10094573/use-mongodb-array-as-stack
- http://stackoverflow.com/questions/10131957/can-you-have-mongo-push-prepend-instead-of-append
|