Skip to content

MongoDB: "revision" field type should be casted to number when createSnapshot #166

@ScripterSugar

Description

@ScripterSugar

Hi.

I've experienced wrong order issue while querying snapshots as I stored my snapshots with "string" typed revisions, and I think the library should force revision inputs in number type because string typed revisions cause sort issues when we query documents like this:

> db.snapshots.find({ aggregateId: "NEWSTREAMID", context: "User_Snapshot"}).sort({revision: -1}).pretty()
{
        "_id" : "5f2138f1f3969e93542e2b2c",
        "id" : "5f2138f1f3969e93542e2b2c",
        "streamId" : "NEWSTREAMID",
        "aggregateId" : "NEWSTREAMID",
        "aggregate" : "User",
        "context" : "User_Snapshot",
        "commitStamp" : ISODate("2020-07-29T08:53:05.651Z"),
        "revision" : "24",
        "version" : null,
        "data" : "24"
}
{
        "_id" : "5f213990f3969e93542e2b2e",
        "id" : "5f213990f3969e93542e2b2e",
        "streamId" : "NEWSTREAMID",
        "aggregateId" : "NEWSTREAMID",
        "aggregate" : "User",
        "context" : "User_Snapshot",
        "commitStamp" : ISODate("2020-07-29T08:55:44.575Z"),
        "revision" : "124",
        "version" : null,
        "data" : "124"
}
...

document with revision "24" comes out first even if there's a document with revision "124" and there's no errors nor warnings when I save my snapshot with string-value revisions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions