【发布时间】:2019-06-24 04:51:51
【问题描述】:
我正在尝试通过将时间戳添加到之前缺少时间戳的所有行来迁移我的数据库。我已经使用 _id 计算了 createdAt 时间戳,但我无法设置时间戳。我在这里做错了什么? 有人可以帮忙吗?
let Question = db.model('Question');
let items = await Question.findWithDeleted();
let processedIds = items.map((q) => q._id);
processedIds.forEach(function (id) {
const timestamp = id.getTimestamp();
// const date = new Date(parseInt(timestamp, 16) * 1000);
// echo(timestamp)
Question.update({ "_id": id }, { "$set": { createdAt: timestamp } }, (h) => {
console.log(h);
});
});
这是模型:
const Question = new Schema({ “类型”: { 类型:字符串, 修剪:真的, 枚举:Object.values(问题类型), required: '问题类型是必需的' }, “文本”: { 类型:字符串, 要求:真 }, "desc": NotRequiredStringSchema, “选项”: [{ “id”:对象 ID, “名称”:NotRequiredStringSchema, “helperText”:NotRequiredStringSchema, “icon_key”:NotRequiredStringSchema, “icon_url”:NotRequiredStringSchema, “icon_svg”:NotRequiredStringSchema }], “placeHolder”:NotRequiredStringSchema, “buttonPosition”:NotRequiredStringSchema, “buttonText”:NotRequiredStringSchema, "buttonHoverText": NotRequiredStringSchema, “helperText”:NotRequiredStringSchema, “最大”:数字, “分钟”:数字, “默认”:混合, “icon_key”:NotRequiredStringSchema, “icon_url”:NotRequiredStringSchema, “icon_svg”:NotRequiredStringSchema, "showTick": { type: Boolean, required: false, default: false }, “朗”:{ 要求:真, 类型:地图, 的: { 类型:地图, 的:字符串 } } }, { 时间戳:真 });【问题讨论】:
-
你能发布架构吗
-
您现在可以查看@KalanaDemel 吗?
-
您要在现有记录上添加时间戳还是在新创建或更新的记录上添加时间戳。
-
@Abhinav Jain,检查解决方案是否有帮助