简体   繁体   中英

Parameter "obj" to Document() must be an object, got 14

Using mongoose. I'm trying to save a value with submit and post in a hbs form, when I submit it and look it in the local host web it shows me "Parameter "obj" to Document() must be an object, got 14".

var express = require('express');
var router = express.Router();
var {grades} = require('../modeloUser');
const buscar ={};
const bodyParser = require('body-parser');
var {Save} = require ('../models/Save');

router.get('/', function(req, res, next) {

//console.log(texto);
  buscar.guardar()

  .then(a=>{
    res.render('obtener',{prop: a});
    
  })
});

router.post('/save', (req, res) => {
    

  const save =Save(`${req.body.fname}`)
  console.log("valor esperado"+save);
  return save;


});

  buscar.guardar = async()=>{

    const notes = await grades.find({student_id:{$eq:14}});
    return notes; 
    
  }
    

  module.exports = router;
  //module.exports =buscarPorCoincidenciaTodos;

This is my model

const saveSchema = new mongoose.Schema(
    {
      busqueda:Number
   },{
    timestamp:true
   }

 );
 
 const Save = new mongoose.model('Save',saveSchema);


module.exports ={Save}

Your syntax doesn't make sense.

Read the docs: https://mongoosejs.com/docs/

It should look like that:

const save = new Save({
  busqueda: body.req.fname
})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM