node.js - Mongorito: save(...).then is not a function -
i tried similar example given on readme.md file:
var mongorito = require('mongorito'); var model = mongorito.model; mongorito.connect('mongodb://localhost:27017/cr-test'); class user extends model { collection() { return 'users'; } } var user1 = new user({ name: "james gosling", email: "user1@gmail.com", password: "changeme" }); user1.save().then(() => { console.log('user created'); }); when run node --harmony server.js error:
user1.save().then(() => { ^ typeerror: user1.save(...).then not function @ object.<anonymous> (...\app\server.js:24:14) @ module._compile (module.js:398:26) @ object.module._extensions..js (module.js:405:10) @ module.load (module.js:344:32) @ function.module._load (module.js:301:12) @ function.module.runmain (module.js:430:10) @ startup (node.js:141:18) @ node.js:980:3 could explain me how fix that?
the readme on github outdated, project's website states:
mongodb odm node.js based on es6 generators.
no callbacks or promises.
it uses generators, can find example of on getting started page:
'use strict'; function* saveuser () { var user1 = new user({ name: "james gosling", email: "user1@gmail.com", password: "changeme" }); yield user1.save(); } in order generators work, must use 'use strict;' , function* syntax. github project has additional examples.
also, starting node v4, no longer need --harmony (now synonym of --es_staging) flag generators.
Comments
Post a Comment