mongoose-schema

MongoDB/Mongoose: On save > Push comment into array, in the array you'll see comment + date

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-25 01:25:48
问题 I have a mongoose model const clientSchema = mongoose.Schema({ Created: { type: String }, kundnr: { type: String, unique: true, required: true }, namn: { type: String }, adress: { gata: String, postkod: Number, stad: String }, kontakt: { email: String, telefon: Number, }, company: { type: mongoose.Schema.Types.ObjectId, ref: 'Company' }, notering: [{ type: String, }], lan: [{ type: String }] }, { timestamps: true }); module.exports = mongoose.model('Client', clientSchema); ` and then theres

How to create a Mongoose schema that saves input as html in mongodb

天涯浪子 提交于 2019-12-24 19:29:57
问题 I am creating a blog website with an admin panel in which a user can write the body of the blog's content in the text editor tinyMCE. Currently my schema for blog body is set to string but everytime I write a blog you can see the html marks around the blog and the markup is not recognized as html. Is this an issue with the schema being set to string? 回答1: I use it in my projects in a similar way. I save tinyMCE content to mongo as a string and thus is saved with the html tags. If you want

Pre remove event not firing for mongoose schema?

好久不见. 提交于 2019-12-24 16:52:45
问题 This isn't firing! No idea why, would really appreciate help here. Booking.find({_id: key}).remove(function(err, result){ if (err) { console.err("ERR", err) } else { console.log("remove result", result); } }) BookingSchema.pre('remove', function (next) { console.log("THIS ID", this._id); next(); }); 回答1: Per the doc, There is no query hook for remove() , only for documents. If you set a 'remove' hook, it will be fired when you call myDoc.remove() , not when you call MyModel.remove() . Then

Pre remove event not firing for mongoose schema?

谁说胖子不能爱 提交于 2019-12-24 16:51:26
问题 This isn't firing! No idea why, would really appreciate help here. Booking.find({_id: key}).remove(function(err, result){ if (err) { console.err("ERR", err) } else { console.log("remove result", result); } }) BookingSchema.pre('remove', function (next) { console.log("THIS ID", this._id); next(); }); 回答1: Per the doc, There is no query hook for remove() , only for documents. If you set a 'remove' hook, it will be fired when you call myDoc.remove() , not when you call MyModel.remove() . Then

how to add new array in body.history.. nodejs

夙愿已清 提交于 2019-12-24 08:13:14
问题 i have Job history schema i want to push other data in History array..how do this..because its update my old Job history i want new one array add in Job history. var JobChangeHistorySchema = new Schema({ datetime: { type: Date, default: Date.now }, changetype: { type: String, default:''}, details: { type: String, default:''}, updated_by: { type: String, default:''} }); import JobHistory from './job_models/job_changehistory.model'; req.body.history = new JobHistory({ changetype: 'eesss',

How to handle hyphens in GraphQL Schema definitions

久未见 提交于 2019-12-24 01:17:06
问题 My mongoose schema is as follows var ImageFormats = new Schema({ svg : String, png-xlarge : String, png-small : String }); When I translate this into a GraphQL Schema, this is what I try export var GQImageFormatsType: ObjectType = new ObjectType({ name: 'ImageFormats', fields: { svg : { type: GraphQLString }, 'png-xlarge': { type: GraphQLString }, 'png-small' : { type: GraphQLString } } }); GraphQL Returns the following error: Error: Names must match /^[_a-zA-Z][_a-zA-Z0-9]*$/ but "png-xlarge

(node:71307) [DEP0079] DeprecationWarning

家住魔仙堡 提交于 2019-12-23 09:25:55
问题 Try to update MongoDB document Getting Deprecation Warning as (node:71307) [DEP0079] DeprecationWarning: Custom inspection function on Objects via .inspect() is deprecated Node version v10.5.0, db version v3.6.5, Mongoose version mongoose@4.1.12 Campground.findById(campgroundId, function(err, campground){ if(err){ console.log(err); } else { console.log(campground.celebrity); Celebrity.create(celebrityData, function(err, celebrity){ if(err){ console.log(err); } else { //save comment celebrity

Mongoose: Filter collection based on values in another collection

谁说胖子不能爱 提交于 2019-12-23 02:54:40
问题 Consider documents that contain an arrays of ID of another collection, how can I find documents applying a filter based on the related collection using mongoose? I can't find my error Installation.aggregate( [ // Stage 1 { $lookup: { from: "users", localField: "_id", foreignField: "_id", as: "Users" } }, // Stage 2 { $unwind: { path: "$Users" } }, // Stage 3 { $match: {"Users.Email1" : "test@test.com"} }, { $sort: { _id: -1 } }, { $limit: 10 } ] ,function (err, installations) { console.log

MongoDB E11000 duplicate key error

大兔子大兔子 提交于 2019-12-21 12:35:37
问题 I have a model that keeps erroring out after the first POST. I'm creating a scheduling application, which is X number of days, with rooms, and time slots for the rooms. The issue I'm having is creating Day Objects in the database. For sake of easy reading I'm just going to have a single key value pair day.model.js var mongoose = require('mongoose'); // Day Schema var daySchema = mongoose.Schema({ name:{ type: String, required: true, }, createdAt:{ type: Date, default: Date.now } }); var Day =

Validate object against Mongoose schema without saving as a new document

删除回忆录丶 提交于 2019-12-21 12:27:02
问题 I'm trying to validate some data that will be inserted into a new document, but not before a lot of other things need to happen. So I was going to add a function to the static methods that would hopefully validate objects in an array against he model schema. Heres the code thus far: module.exports = Mongoose => { const Schema = Mongoose.Schema const peopleSchema = new Schema({ name: { type: Schema.Types.String, required: true, minlength: 3, maxlength: 25 }, age: Schema.Types.Number }) /** *