MongoError:filter参数必须是一个对象 [英] MongoError: filter parameter must be an object

查看:387
本文介绍了MongoError:filter参数必须是一个对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个休息api我有Post / Movies的终点:Request body应该只包含电影标题,并且它的存在应该被验证基于传递的标题,其他电影细节应该从thememoviedb获取,并保存到应用程序数据库。

I am creating a rest api I have end point for Post/Movies: Request body should contain only movie title, and its presence should be validated Based on passed title, other movie details should be fetched from thememoviedb,and saved to application database.

app.post('/movies', (req, res) => {
        request('https://api.themoviedb.org/3/discover/movie?callback=JSONP_CALLBACK&sort_by=popularity.desc&api_key=2931998c3a80d7806199320f76d65298', function (error, response, body) {
            console.log('error:', error); // Print the error if one occurred and handle it
            console.log('statusCode:', response && response.statusCode); // Print the response status code if a response was received

          });
        db.collection('movies').findOneAndUpdate(req.body.title,{
            title: 'Avengers',
        },(err, result) => {
            if (err) {
                res.send({
                    'error': 'An error has occured'
                });
            } else {
                res.send(result.ops[0]);
            }
        });
});

当我运行应用程序时出现此错误,我在这里做错了什么?我是nodejs的新手,所有这些东西只是学习

when I run the app I get this error, what am I doing wrong here,? am new to nodejs and all this stuff just learning

推荐答案

尝试以下方法,

db.collection('movies').findOneAndUpdate({title:req.body.title},{
          $set:{
           'Avengers'
          }})

这篇关于MongoError:filter参数必须是一个对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆