Typeerror: Cannot Create Property '_Id' on String

TypeError: Cannot create property '_id' on string

body is the JSON string, to convert it to JSON object, use JSON.parse(body)

app.post('/data', (req, res) => {
let url = 'https://api.themoviedb.org/3/movie/401478/reviews?api_key=4d9c9de3bdf0d3b6837c49c086e3b190';
request(url, function (error, response, body) {

// convert to JSON
var bodyJson = JSON.parse(body)

db.collection('data').insert(bodyJson, (err, result) => {
if (err) {
res.send({
'error': 'An error has occured'
});
} else {
res.send(result.ops[0]);
}
});
});
});

TypeError: Cannot create property '_id' on string... even after using JSON.Parse?? (MongoDB /Node.js / Twitter API)

I found the solution. MongoDB needs (a must have!) to have a document (eg. text = {screen_name: name, text: text}). My correction is the following:

var text = JSON.parse(string2);
var myobj = {texto: text};

console.log("hi "+text);
dbo.collection("datos_sentimiento").insertOne(myobj, function(err, res) {
if (err) throw err;
console.log("1 document inserted");
db.close();
});

Dynamic object keys... Cannot create property on string

There are 2 problems.

  • The assignment operator resolves to a value of the value assigned. So
setContentData(oldData[e.target.id] = e.target.value)

is like

oldData[e.target.id] = e.target.value;
setContentData(e.target.value)

which is causing issues because in the next render, contentData becomes a string instead of the object.

  • Never mutate state in React. Instead, create a new object:
const onChange = (e) => {
setContentData({
...contentData,
[e.target.id]: e.target.value
});
};

TypeError: Cannot create property '_id' on number '1' when trying to submit to MondoDB

I figured it out. I misunderstood what words[key] did and was just accessing the value as opposed to submitting an object. I fixed this by creating an object an changing the function from inserOne() to insertMany(). The change takes place in the last for loop:

MongoClient.connect(process.env.MONGODB_URI || process.env.DB_CONNECTION, { useUnifiedTopology: true, useNewUrlParser: true }, function (err, db) {            if (err) throw err;            const dbo = db.db("mydb");            const messageTable = dbo.collection("comments");            for(var key in words){                let myobj =                 [{                     word: key,                    message: words[key]                }];                messageTable.insertMany(myobj, function(err, res){                    if (err) throw err;                    console.log("documents inserted");                });            }        })

TypeError: Cannot create property 'next' on string '/:id'

It seems you forgot .route here:

tourRouter('/:id').

It should be

tourRouter.route('/:id').

MongoDB Error: Cannot create property '_id' on string

I don't know where you are getting the jsonHash variable from but I think you are doing unecessary JSON-handling here. You are also inserting the wrong variable, you want to insert objHash which is a valid object to insert, now you are inserting jsonHash which is just a string. JSON.stringify(objHash); is not doing anything as you are not saving the JSON returned from the function. I think you want something like this?

var objHash = {
hashtag: "",
popularity:1
};
objHash.hashtag = req.body.hashtag;
collection(HASHTAG_COLLECTION).insert(objHash);

ERROR TypeError: Cannot create property 'id' on number '1' . Angular

here the SampleRequest which you are exporting is undefined, as you mentioned

export class SampleRequest {
title: string;
user: { id: number};
category: { id: number};
description: string;
quantity: number;
}

it is a class you need to initialize like

sampleRequest: SampleRequest = new SampleRequest();

by this way, you will get all your sample request property in your this.sampleRequest

TypeError: Cannot create property '_fullPath' on string ''

This error was generated with the version 6.1.3 of mongoose .
To prevent this horrible fault from mongoose team please downgrade it to 6.1.2



Related Topics



Leave a reply



Submit