2
Good morning, I am unable to 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 You’re making a mistake.
db.users.insert(
{
_id: getNextSequence("userid"),
name: "Sarah C."
}
)
Failed to execute script.
Error: Referenceerror: getNextSequence is not defined :@(shell):3:6