我在nodejs app
中有这个模型var mongoose = require('mongoose'),
Schema = mongoose.Schema;
var ServiceSchema = new Schema({
Taxy: {
type: mongoose.Schema.Types.ObjectId,
ref: 'Taxy',
required: 'Taxy cannot be blank'
},
User: {
type: mongoose.Schema.Types.ObjectId,
ref: 'User',
required: 'User cannot be blank'
},
Servicio: String,
Minutos: Number,
Costo: Number,
Desc: String,
From: String,
To: String,
created: {
type: Date,
default: Date.now
}
});
mongoose.model('Service', ServiceSchema);
我已经浏览了几天而且我还没有找到一个从模型服务生成随机数据的框架,比如
var Service = require('mongoose').model('Admin').schema;
var jsondata = generateRandomeFromModel(Service)
答案 0 :(得分:1)
您可以使用mongoose-fakery
模块生成test
数据
示例:强>
var mongoose = require('mongoose')
, Schema = mongoose.Schema;
var UserSchema = new Schema({
name: String,
surname: String
});
mongoose.model('User', UserSchema);
In your tests or fixture files:
var fakery = require('mongoose-fakery');
fakery.fake('user', mongoose.model('User'), {
name: 'john',
surname: 'doe'
});
您可以使用完整参考here
答案 1 :(得分:0)
我找到了两年前创建的可行解决方案。我也对其进行了测试。