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
Weird Behaviour With on Click Event Binding; Event Not Firing
How to Tell If a Dom Element Is Visible in the Current Viewport
Deselect All Options in Multiple Select With 1 Option
Usestate Hook Not Updating a Value
Javascript Check If Character Is a Vowel
How to Customize Header Cell in Pdf Using Jspdf-Autotable Plugin
Use JavaScript to Place Cursor At End of Text in Text Input Element
Passing Value from Java to JavaScript
Postman Test - Validating String Values in an Object in an Array
Pass Variable from Android to JavaScript Launched in Webview
How to Hide Blinking Cursor in Input Text
How to Store Multiple Items in Local Storage
Multi Select Drop Down With Checkbox
Is It Okay to Call Onclick on an Anchor Tag in Reactjs
Single Quotes in String With Jquery Ajax
Barcode Scanner for Mobile Phone for Website in Form
Error: Permission Denied to Access Property "Document"
Navigationduplicated Navigating to Current Location ("/Search") Is Not Allowed