我尝试了与readme.md文件中给出的示例类似的内容:
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');
});
当我运行node --harmony server.js
时出现此错误:
user1.save().then(() => {
^
TypeError: user1.save(...).then is not a function
at Object.<anonymous> (...\app\server.js:24:14)
at Module._compile (module.js:398:26)
at Object.Module._extensions..js (module.js:405:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Function.Module.runMain (module.js:430:10)
at startup (node.js:141:18)
at node.js:980:3
有人可以解释我怎么解决这个问题?
答案 0 :(得分:1)
GitHub上的自述文件已过时,project's website现在声明:
基于ES6生成器的Node.j的MongoDB ODM。
没有回调或承诺。
它使用生成器,可以在getting started页面上找到一个示例:
'use strict';
function* saveUser () {
var user1 = new User({
name: "James Gosling",
email: "user1@gmail.com",
password: "changeme"
});
yield user1.save();
}
为了让生成器工作,您必须使用'use strict;'
和function*
语法。此GitHub project还有其他示例。
此外,从Node v4开始,您不再需要生成器的--harmony
(now a synonym of --es_staging
)标记。
答案 1 :(得分:0)
或者你也可以这样做......但在这里你只能执行一个声明
profile = ["HandBrakeCLI","-i",input,"-o","output","-e","x264"]
cp = subprocess.Popen(profile, stderr=subprocess.PIPE, strout=subprocess.PIPE, close_fds=True)
bar = Bar(label="Encoding %s" % input, width=30, expected_size=10000, every=1)
bar.show(0)
line = ""
c = 0
while True:
nl = cp.stdout.read(1)
if nl == '' and cp.poll() is not None:
break # Aborted, no characters available, process died.
if nl == "\n":
line = ""
elif nl == "\r":
# regex match for % complete and ETA, assuming the regex is ok.
matches = re.match( r'.*(\d+\.\d+)\s%.*ETA\s(\d+)h(\d+)m(\d+)s', line.decode('utf-8') )
if matches:
print( matches.group() )
# do something
line = ""
else:
line += nl
error = cp.stderr.read()
success = "Encode done!" in error