如何使 MongoDB 本身或 MongoDB 的某些 Node.js 驱动程序要求我的文档成为某个预定义架构的子集。我听说这是可能的,但到目前为止我还没有找到确切的方法。
最佳答案
我知道mongoose.js允许您定义模式。 例如:
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var blogSchema = new Schema({
title: String,
author: String,
body: String,
comments: [{ body: String, date: Date }],
date: { type: Date, default: Date.now },
hidden: Boolean,
meta: {
votes: Number,
favs: Number
}
});
通过它,您可以定义集合的架构。
关于javascript - 使用 node.js 驱动程序强制执行特定的 MongoDB 模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26185991/