So the weirdest thing is going on. I have a coffeescript class which I use to construct a mongoose schema.
module.exports = class Profit
constructor: (Schema, mongoose) ->
@DailyProfitSchema = new Schema(
profit:
type: Number
default: 0
percent_profit:
type: Number
default: 0
day:
type: Number
default: 0
)
@Day = mongoose.model('Day', @DailyProfitSchema)
@local_day = null
and here is my update function
update: (funds) ->
if @local_day?.day is not date.getDate()
# new day
@local_day = new @Day()
@local_day.save(
(err, res) ->
console.log "saving local day"
if err?
console.log err
)
the weird thing is that when I update
Profit = require '../new_profit'
mongoose = require('mongoose')
mongoose.connect('mongodb://localhost/test')
Schema = mongoose.Schema
profit = new Profit(Schema, mongoose)
funds =
amount: 100
profit.update(funds)
nothing is outputted, as opposed to the expected saving local day which should be outputted when @local_day.save() is called.
Okay so this is weird enough, but what's even weirder is that when I change the update function to this
update: (funds) ->
if @local_day?.day is not date.getDate()
# new day
@local_day = new @Day()
console.log @local_day.save() # this is the line I added
@local_day.save(
(err, res) ->
console.log "saving local day"
if err?
console.log err
)
I get the even more unexpected result
undefined
saving local day
What could possibly be causing this?
Also I'm not sure if it's relevant but I'm running mongod as a background process to make the local db work.
Update: Well whatever it was, the problem went away when I stopped using the local db mongodb://localhost/test