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

Crushed when edit document #1405

Open
maicss opened this issue Feb 2, 2024 · 3 comments
Open

Crushed when edit document #1405

maicss opened this issue Feb 2, 2024 · 3 comments

Comments

@maicss
Copy link

maicss commented Feb 2, 2024

Document:

{
    _id: ObjectId('65bb6236bf621c8578d92e43'),
    dates: {
        date: ISODate('2012-05-14T16:20:09.314Z'),
        new_date: ISODate('2024-02-01T09:19:50.457Z'),
        alternative: ISODate('2024-02-01T09:19:50.457Z')
    },
    pdf: '',
    photo: '',
    audio: '',
    video: '',
    bool: true,
    string: 'hello world!',
    'list of numbers': [
        123,
        1.11e+89,
        4.4,
        -12345.765
    ],
    reference: DBRef('collection1', '5ca4bbc7a2dd94ee581623b0'),
    ts: Timestamp({ t: 807303372, i: 1 }),
    minkey: MinKey(),
    maxkey: MaxKey(),
    func: Code(function() { alert('Hello World!') })
}

Result:

file:///Users/Maicss/workspace/mongo-express/lib/routes/document.js:88
    docBSON._id = req.document._id;
                ^

TypeError: Cannot create property '_id' on string ''
    at exp.updateDocument (file:///Users/Maicss/workspace/mongo-express/lib/routes/document.js:88:17)
    at Layer.handle [as handle_request] (/Users/Maicss/workspace/mongo-express/node_modules/express/lib/router/layer.js:95:5)
    at next (/Users/Maicss/workspace/mongo-express/node_modules/express/lib/router/route.js:144:13)
    at mongoMiddleware (file:///Users/Maicss/workspace/mongo-express/lib/router.js:267:5)
    at Layer.handle [as handle_request] (/Users/Maicss/workspace/mongo-express/node_modules/express/lib/router/layer.js:95:5)
    at next (/Users/Maicss/workspace/mongo-express/node_modules/express/lib/router/route.js:144:13)
    at Route.dispatch (/Users/Maicss/workspace/mongo-express/node_modules/express/lib/router/route.js:114:3)
    at Layer.handle [as handle_request] (/Users/Maicss/workspace/mongo-express/node_modules/express/lib/router/layer.js:95:5)
    at /Users/Maicss/workspace/mongo-express/node_modules/express/lib/router/index.js:284:15
    at param (/Users/Maicss/workspace/mongo-express/node_modules/express/lib/router/index.js:365:14)

Cause:
https://github.com/mongo-express/mongo-express/blob/master/lib/routes/document.js#L84
docBSON = bson.toBSON(doc); got an empty string, so there is no _id attribute on a string.
Is this an upstream bug of https://github.com/rtritto/query-parser?

@maicss
Copy link
Author

maicss commented Feb 2, 2024

And two questions:

1 readme example document

Use example document in Readme: https://github.com/mongo-express/mongo-express/blob/master/README.md?plain=1#L358 got an error:

Timestamp(ISODate(), 1)
BSONError: Timestamp constructed from { t, i } must provide t as a number

2 package source

Why not use https://github.com/mongodb-js/devtools-shared/tree/main/packages/query-parser instead of https://github.com/rtritto/query-parser?

@rtritto
Copy link
Member

rtritto commented Feb 2, 2024

2 package source

Why not use https://github.com/mongodb-js/devtools-shared/tree/main/packages/query-parser instead of https://github.com/rtritto/query-parser?

I did the branch rtritto/query-parser#fix-mismatch-bindata-subtype as the PR on mongodb-js/query-parser to fix #1249 and it wasn't merged.

To patch the issue #1249, I used #1289 (branch rtritto/query-parser#4.0.0-fix-bindata).

On the 8/1/24, the repository mongodb-js/query-parser is moved to repository mongodb-js/devtools-shared/query-parser and mongodb-query-parser v4.0.2 was released.

Currently the #1249 has not yet been fixed on mongodb-js/devtools-shared/query-parser.

mongodb-js/query-parser issues were tracked on GitHub while mongodb-js/devtools-shared/query-parser issues are tracked on Jira.

mongodb-js/query-parser repository is removed with my PR, so it's needed to open an issue to Jira.

If it's not needed, I'll wait the fix for #1249 on mongodb-js/devtools-shared/query-parser and then replace the dependency in mongo-express.

Edit: On Jira I opened issue https://jira.mongodb.org/browse/COMPASS-7644

FYI @shakaran @BlackthornYugen

@rtritto
Copy link
Member

rtritto commented Feb 3, 2024

Result:

file:///Users/Maicss/workspace/mongo-express/lib/routes/document.js:88
    docBSON._id = req.document._id;
                ^

TypeError: Cannot create property '_id' on string ''
    at exp.updateDocument (file:///Users/Maicss/workspace/mongo-express/lib/routes/document.js:88:17)
    at Layer.handle [as handle_request] (/Users/Maicss/workspace/mongo-express/node_modules/express/lib/router/layer.js:95:5)
    at next (/Users/Maicss/workspace/mongo-express/node_modules/express/lib/router/route.js:144:13)
    at mongoMiddleware (file:///Users/Maicss/workspace/mongo-express/lib/router.js:267:5)
    at Layer.handle [as handle_request] (/Users/Maicss/workspace/mongo-express/node_modules/express/lib/router/layer.js:95:5)
    at next (/Users/Maicss/workspace/mongo-express/node_modules/express/lib/router/route.js:144:13)
    at Route.dispatch (/Users/Maicss/workspace/mongo-express/node_modules/express/lib/router/route.js:114:3)
    at Layer.handle [as handle_request] (/Users/Maicss/workspace/mongo-express/node_modules/express/lib/router/layer.js:95:5)
    at /Users/Maicss/workspace/mongo-express/node_modules/express/lib/router/index.js:284:15
    at param (/Users/Maicss/workspace/mongo-express/node_modules/express/lib/router/index.js:365:14)

This issue is related to mongodb-query-parser:

import parser from 'mongodb-query-parser'
parser(`{ func: Code(function() { alert('Hello World!') }) }`)

The output is an empty string instead of the converted object.


1 readme example document

Use example document in Readme: https://github.com/mongo-express/mongo-express/blob/master/README.md?plain=1#L358 got an error:

Timestamp(ISODate(), 1)
BSONError: Timestamp constructed from { t, i } must provide t as a number

The example and the link are outdated.

The example should be at least:

Timestamp({ t: <high>, i: <low> })

And the doc: https://www.mongodb.com/docs/manual/reference/bson-types/#timestamps

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

No branches or pull requests

2 participants