Clone and edit this document
Runkit
Runkit
home page
user forum
new notebook
clone notebook
download notebook
support & documentation
log in
sign up
new notebook
help & feedback
clone this notebook
download this notebook
Sign In
Sign Up
RunKit + npm: mongoose-jsonschema
node v8.17.0
version:
master
endpoint
share
tweet
var mongoose = require('mongoose'); var Schema = mongoose.Schema const FbProfileSchema = new Schema({ fb_id: { type: String, required: true, index: { unique: true } }, first_name: String, last_name: String, }, { toJSON: { transform: function (doc, ret) { var key = ret._id.toHexString(); delete ret._id; ret._id = key; } } }); const UserModel = new Schema({ email: { type: String, required: true, index: { unique: true } }, fbProfile: { type: Schema.ObjectId, ref: FbProfileSchema }, }); var FbProfile = mongoose.model('FbProfile', FbProfileSchema); var User = mongoose.model('User', UserModel); var json = "{\"fbProfile\":{\"_id\":\"5a38f1aff8920ebf2b098f40\",\"last_name\":\"My Last Name\",\"first_name\":\"My First Name\",\"fb_id\":\"temp_fb_id\",\"__v\":0},\"email\":\"temp.email@gmail.com\",\"__v\":0,\"_id\":\"5a38f1aff8920ebf2b098f41\"}"; var userJSON = JSON.parse(json); var user = new User(userJSON);
Created from: https://npm.runkit.com/mongoose-jsonschema
Loading…
no comments
sign in
to comment