Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js Can';t使用express+;基于id更新数据;mongo+;节点_Node.js_Mongodb_Express_Objectid - Fatal编程技术网

Node.js Can';t使用express+;基于id更新数据;mongo+;节点

Node.js Can';t使用express+;基于id更新数据;mongo+;节点,node.js,mongodb,express,objectid,Node.js,Mongodb,Express,Objectid,我对node/express/mongo完全是个新手。我正在努力学习,但一个错误正在结束我的一天。不知道为什么。谷歌搜索了很多,仍然找不到合适的解决方案。下面是我在pastebin的代码,您可以在这里找到我的代码 尽管我使用objectID for mongo从url获取id参数,但我发现以下错误一直在发生。你能帮我一下吗 Error: Error: Argument passed in must be a single String of 12 bytes or a string of 2

我对node/express/mongo完全是个新手。我正在努力学习,但一个错误正在结束我的一天。不知道为什么。谷歌搜索了很多,仍然找不到合适的解决方案。下面是我在pastebin的代码,您可以在这里找到我的代码

尽管我使用objectID for mongo从url获取id参数,但我发现以下错误一直在发生。你能帮我一下吗

Error: 
Error: Argument passed in must be a single String of 12 bytes or a string of 24 hex characters
at new ObjectID (c:\Users\AD LORD\Desktop\learning-node\node_modules\bson\lib\bson\objectid.js:50:11)
at ObjectID (c:\Users\AD LORD\Desktop\learning-node\node_modules\bson\lib\bson\objectid.js:31:42)
at app.get (c:\Users\AD LORD\Desktop\learning-node\server.js:35:44)
at Layer.handle [as handle_request] (c:\Users\AD LORD\Desktop\learning-node\node_modules\express\lib\router\layer.js:95:5)
at next (c:\Users\AD LORD\Desktop\learning-node\node_modules\express\lib\router\route.js:137:13)
at Route.dispatch (c:\Users\AD LORD\Desktop\learning-node\node_modules\express\lib\router\route.js:112:3)
at Layer.handle [as handle_request] (c:\Users\AD LORD\Desktop\learning-node\node_modules\express\lib\router\layer.js:95:5)
at c:\Users\AD LORD\Desktop\learning-node\node_modules\express\lib\router\index.js:281:22
at param (c:\Users\AD LORD\Desktop\learning-node\node_modules\express\lib\router\index.js:354:14)
at param (c:\Users\AD LORD\Desktop\learning-node\node_modules\express\lib\router\index.js:365:14)

由于没有得到任何答案,我设法解决了这个问题。似乎我的参数设置不正确,错误即将发生,因此我更新了我的路线,如下所示:

// update quote
app.post( '/update/edits', ( req, res ) => {
    db.collection('quote').update (
        { _id: ObjectId(req.body.quoteID) },
        { $set: {
            name: req.body.name,
            quote: req.body.quote
            }
        }, function (err, result) {
            if (err) {
                req.flash('error', err);
            } else {
                req.flash('success', 'Quote updated successfully');
            }
            res.redirect('/');
     });
});
顺便说一句,你可以在我的github中检查完成的CRUD系统,如果它有任何帮助的话