我想使用环回自动增加 mongodb 文档编号。
我在 mongo 中做了功能
function getNextSequence(name) {
var ret = db.counters.findAndModify(
{
query: { _id: name },
update: { $inc: { seq: 1 } },
new: true
}
);
return ret.seq;
}
db.tweet.insert(
{
"_id" : getNextSequence("userid"),
"content": "test",
"date": "1",
"ownerUsername": "1",
"ownerId": "1"
}
)
Run Code Online (Sandbox Code Playgroud)
它在 mongo shell 中工作。
但是,当我使用 loopback.js 浏览器(http://localhost:3000/explorer/)插入时,它不起作用。显示 400 错误(SytaxError)代码。
我不能在环回休息 API 中使用 mongo 函数?
我认为问题是这一行中的引号getNextSequence("userid"),