我想对集合中的文档进行排序,我知道文档保存在FIFO中。但我希望根据我的方便保存文档。
router.post('/', function(req, res, next) {
Users.create({
firstName: req.body.firstName
})
.then((user) => {
user.password = user.generateHash(req.body.password);
user.save();
console.log('User created ', user);
res.statusCode = 200;
res.setHeader('Content-Type', 'application/json');
res.json(user);
}, (err) => next(err))
.catch((err) => next(err));
});
从上面的代码中,文档保存如下:
{
"_id" : ObjectId("5d40914a59b5775718f13f9e"),
"firstName" : "final8",
"createdAt" : ISODate("2019-07-30T18:49:46.549Z"),
"updatedAt" : ISODate("2019-07-30T18:49:46.604Z"),
"__v" : 0,
"password" :
"$2b$08$H1cxDRUWDEDlcy.ZspiiKuzIXnOiAsrFtPywXnYDIqYa00xp1VTQG"
}
我希望将它们另存为:
{
"_id" : ObjectId("5d4083b78ead7e648c1e733d"),
"firstName" : "final",
"password" :
"$2b$08$JjKUhsH5w0YN/PyyDPUaLOX3kffuZfqKMz8IU6r0UiD.1m9xRQHtm",`
"createdAt" : ISODate("2019-07-30T18:49:46.549Z"),
"updatedAt" : ISODate("2019-07-30T18:49:46.604Z"),
"__v" : 0
}