How to insert a string array values record in couchbase bucket?

127 Views Asked by At

I'm working on the couchbase database with node js. I need to insert form-data array values to My DB. While inserting records it will show errors in Schema. Error: Expected languages non-object type {"type":"string"} but got object

I Try this one for converting array values and push to array format

 var languagesobj= [];
    var item = req.body.languages;
     languagesobj.push(item);
    console.log(item);

It will show like array inside array.

[ [ '" Assamese"',
    '"English"',
    '"Malayalam"',
    '"Nepali"',
    '"Tamil"' ] ]

This is my model file usermodel.js

var ottoman = require('ottoman');
var userMdl = ottoman.model('users{
    userId: 'string',
languages:'string',
});
module.exports = userMdl;

Controller.js

var users = require('../../model/users/users.model');
var bodyParser = require('body-parser');
var urlencodedParser = bodyParser.urlencoded({ extended: false });
const couchbase = require('couchbase');
exports.usercreate = function (req, res) {
 var usersData = {
          languages: req.body.languages
        }
           users.create(usersData, function (err, done) {
                     if (err) {
                       res.status = 400;
                       res.send(err.toString());
                       return;
                      }
                      res.status(200).json({ status: "success", resCode: 200, msg: "User Added Successfully",userdetails:done });
                  });
           }

This is the response I am getting from the mobile app.

 ['"Kashmiri"', '"Malayalam"', '"Manipuri"', '"Nepali"' ].

I need to store this response like

"languages": [
    "tamil",
    "english",
    "ma",
    "UT",
    "mt"
  ],

Kindly help someone i'm new to node js and couchbase

0

There are 0 best solutions below