Good morning, I can not create and execute this function in mondodb 3.4 I'm following this tutorial: Create an Auto-Incrementing Sequence Field
Error Error: ReferenceError: getNextSequence is not defined: @ (shell): 3: 6
function getNextSequence(name) {
var ret = db.counters.findAndModify(
{
query: { _id: name },
update: { $inc: { seq: 1 } },
new: true
}
);
return ret.seq;
}
When I run this command on mongodb This is giving error.
db.users.insert(
{
_id: getNextSequence("userid"),
name: "Sarah C."
}
)
Failed to execute script.
Error: ReferenceError: getNextSequence is not defined: @ (shell): 3: 6