Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Fish.find is not a function at model.UserSchema.methods.fishes
- // Require mongoose to create a model.
- var mongoose = require('mongoose'),
- User = require('./user.js');
- // Create a schema of your model
- var fishSchema = new mongoose.Schema({
- name: String,
- category: String,
- user: { type: mongoose.Schema.Types.ObjectId, ref:'User' }
- });
- // Create the model using your schema.
- var Fish = mongoose.model('Fish', fishSchema);
- // Export the model of the Fish.
- module.exports = Fish;
- var mongoose = require('mongoose'),
- Schema = mongoose.Schema,
- bcrypt = require('bcrypt-nodejs'),
- Fish = require('./fish');
- //||||||||||||||||||||||||||--
- // CREATE USER SCHEMA
- //||||||||||||||||||||||||||--
- var UserSchema = new Schema({
- name: { type: String, required: true },
- phoneNumber: {
- type: String,
- required: true,
- index: { unique: true },
- minlength: 7,
- maxlength: 10
- },
- password: { type: String, required: true, select: false }
- });
- // … some bcrypt stuff…
- // Access user's fishes - THIS IS WHAT'S MESSING UP!!
- UserSchema.methods.fishes = function(callback) {
- Fish.find({user: this._id}, function(err, fishes) {
- callback(err, fishes);
- });
- };
- module.exports = mongoose.model('User', UserSchema);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement