我建立了这样的数据库,如何确保某个字段始终具有日期类型,与我创建createIndex的方式类似?
let MongoClient = require('mongodb').MongoClient,
url = "mongodb://localhost:27017/mydb";
MongoClient.connect(url, { useNewUrlParser: true }, function(err, db) {
if (err) throw err;
console.log("Database created!");
var dbo = db.db("booliscraper");
dbo.createCollection("sold", function(err, res) {
if (err) throw err;
console.log("Collection created!");
dbo.collection("sold").createIndex({ "booliId": 1 }, { unique: true })
db.close();
});
});