javascript - mongoose functions only working on second call -
so weirdest thing going on. have coffeescript
class use construct 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 update function
update: (funds) -> if @local_day?.day 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 when 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 outputted, opposed expected saving local day
should outputted when @local_day.save()
called.
okay weird enough, what's weirder when change update function
update: (funds) -> if @local_day?.day not date.getdate() # new day @local_day = new @day() console.log @local_day.save() # line added @local_day.save( (err, res) -> console.log "saving local day" if err? console.log err )
i more unexpected result
undefined saving local day
what possibly causing this?
also i'm not sure if it's relevant i'm running mongod
background process make local db
work.
update: whatever was, problem went away when stopped using local db mongodb://localhost/test
Comments
Post a Comment