When adding a field called date
in mongo db, I can do just:
date: {
type: Date,
default: Date.now
}
and it will automatically add date
field to my new collection when it was created. Is there some way to add a self-incrementing index (id
) to my collections?
Note: I tried to do it on client side, however with every time I push collection with (id
) field, its being deleted from the collection and replaced with _id
which is a long string with random characters. Way to long!
Looking for every hints.
Edit: code responsible for adding use to db
app.post("/users", function (req, res) {
createUser(req.body, function (err, user) {
if (err) {
return res.json(err);
}
return res.json(user);
});
});