-
Notifications
You must be signed in to change notification settings - Fork 371
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
Sort document fields in lexicographic/numeric order #2038
Labels
code/enhancement
Some user-visible feature could work better
community
Issues and PRs assigned to community members
Milestone
Comments
AlekSi
added
the
not ready
Issues that are not ready to be worked on; PRs that should skip CI
label
May 1, 2023
@AlekSi, I faced this issue while working for PR 3931. We might need more than
db.t1.updateOne({_id: 1, y: 3, x: 2}, {$set: {b: 2, d: 4}, $inc: {a: 1}, $push: {e: 5}, $setOnInsert: {c: 3}}, {upsert: true});
// result
[
{
// filter fields are added as it was passed in the command without any ordering
_id: 1,
x: 2,
y: 3,
// fields mentioned in update operators are sorted and processed one by one.
a: 1,
b: 2,
c: 3,
d: 4,
e: [ 5 ]
}
]
db.t1.updateOne({_id: 2}, {$set: {"a.y": 2}, $inc: {"a.x": 1}, $setOnInsert: {"a.z": 3}}, {upsert: true});
// result
[
{
_id: 2,
// fields with dot notations are sorted and processed (similar to previous case)
a: { x: 1, y: 2, z: 3 }
}
]
db.t1.updateOne({_id: 3}, {$set: {x: { c: 3, b: 2}}, $setOnInsert: {a: 1}}, {upsert: true});
// result
[
{
_id: 3,
// sorting is only done for fields at root level
// if the operator has as a field whose value is a document (in our case of `x`), then the value is treated as it is, sorting is not carried out with fields inside that document (value).
a: 1,
x: { c: 3, b: 2 }
}
]
db.t1.updateOne({_id: 3}, {$set: {"x.b": 4, "x.c": 5, "x.d": 6, "x.a": 3}});
// result
[
{
_id: 3,
a: 1,
x: {
// existing nested fields x.c and x.b retained their position
c: 5,
b: 4,
// x.a and x.d are sorted and appended
a: 3,
d: 6
}
}
] Solution
That would solve the above example scenarios. |
9 tasks
AlekSi
removed
the
not ready
Issues that are not ready to be worked on; PRs that should skip CI
label
May 1, 2024
AlekSi
added
code/enhancement
Some user-visible feature could work better
and removed
code/chore
Code maintenance improvements
labels
May 15, 2024
This issue is linked from |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
code/enhancement
Some user-visible feature could work better
community
Issues and PRs assigned to community members
What should be done?
https://www.mongodb.com/docs/manual/reference/operator/update/#behavior
"bar"
comes before"foo"
"7"
comes before"42"
"bar.7"
comes before"bar.42"
Where?
FerretDB/internal/types/document.go
Line 363 in 102b27d
Definition of Done
SortFieldsByKey
added to places where it should be;The text was updated successfully, but these errors were encountered: