【发布时间】:2017-06-01 22:41:12
【问题描述】:
我正在尝试将新字段(日期类型的 LastLoginDate)添加到现有集合中。这是我的示例脚本:
db.createCollection( "MyTestCollection",
{ "validator": { "$or":
[
{ "username": { "$type": "string" } },
{ "notes": { "$type": "string" } }
]
}
}
)
db.getCollectionInfos({name: "MyTestCollection"});
[
{
"name" : "MyTestCollection",
"options" : {
"validator" : {
"$or" : [
{
"username" : {
"$type" : "string"
}
},
{
"notes" : {
"$type" : "string"
}
}
]
}
}
}
]
将新字段LastLoginDate : { $type: "date" } 添加到现有集合“MyTestCollection”的最佳方法是什么。
添加新文档或使用新字段更新现有集合可能会创建此字段。但我不确定如何在新字段上强制执行日期类型。添加新字段后,如果我再次执行以下命令,它不会显示新添加字段的类型验证器。
【问题讨论】:
标签: mongodb mongodb-query