So I'm playing with MongoDb database, I've used so far with Python but now I'm trying to conquer Node.js. I've connected to mongo database with mongoose. Configured following schema:
var recipeSchema = new Schema({
title: String,
img: String,
category: String,
cook_time: String,
method: String,
person_count: String,
short_desc:String,
ingredients: [
{
amount: String,
ingredient: String
}
],
recipe: String,
advice: String
});
var Recipe = mongoose.model('Recipe', recipeSchema);
I have filled database with some autamation procedure in python, and the problem I have is that somehow I got the two unwanted charaters \n on beginning of my title string. I managed to find documents with Mongoose in Node, that has title item which are starting with \n with:
Recipe.find({ title: /\n/ }, 'title', function (err, document) {
if (err) return handleError(err);
console.log(document)
})
I'm little bit newbie in javascript so I'm gonna ask a question which is the best way to replace the \n with nothing (I suppose something like string.replace("\n","")) and update it back to my mongo database?
string.replace("\n", "")is exactly what you'd do. Did you try that?.find({ title: /\n/ }, 'title',...is valid syntax. Also, I don't think Mongo has a find and replace strategy. I would use a cursor and usestring.replace()as you have it.