代码如下: var mongoose = require(‘mongoose’);
mongoose.connect(‘mongodb://localhost/ppl’);
var db = mongoose.connection; db.on('error’, console.error.bind(console, ‘connection error:’)); db.once('open’, function(callback) { // yay! var Schema = mongoose.Schema, ObjectId = Schema.ObjectId;
var NameSchema = new Schema({
name: String
});
var Name = mongoose.model('Name', NameSchema);
for (var i = 0; i < 1000; i++) {
new Name({
name: "hello,world"
}).save(function(err, name) {
console.log(name)
})
};
});
3 回复