在nodejs app中启动mongodb

时间:2016-02-05 03:10:15

标签: node.js mongodb mongoose

我在我的Windows 7计算机上安装了MongoDB v3.0.6,我正在尝试启动数据库。

我有一个运行节点应用程序的命令行窗口和第二个命令行窗口,我在其中导航到'D:/ mongodb / bin'并使用:

mongodb.exe --dbpath d:/mongodb/data

哪个侦听连接,所以我打开了第三个命令行窗口并尝试了这个:

mongodb.exe

这给了我:I CONTROL Hotfix KB2731284 or later update is not installed, will zero out data files MongoDB shell version 3.0.6 connecting to: test

然后,当我在浏览器中运行应用程序时,它崩溃了,我在运行节点应用程序的命令行窗口中遇到了一个红色的'app crashed - blah blah blah'。

我的app.js文件中有这个:

var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/emedb');
var Schema = mongoose.Schema;

// create a schema
var userSchema = new Schema({
  name: String,
  username: {
    type: String,
    required: true,
    unique: true
  },
  password: {
    type: String,
    required: true
  },
  admin: Boolean,
  location: String,
  meta: {
    age: Number,
    locale: String
  },
  created_at: Date,
  updated_at: Date
});

// on every save, add the date
userSchema.pre('save', function(next) {
  // get the current date
  var currentDate = new Date();

  // change the updated_at field to current date
  this.updated_at = currentDate;

  // if created_at doesn't exist, add to that field
  if (!this.created_at)
    this.created_at = currentDate;
  next();
});

// the schema is useless so far
// we need to create a model using it
var User = mongoose.model('User', userSchema);

// make this available to our users in our Node applications
module.exports = User;

我怀疑是我的问题所在。很多人可能会猜到我对此很新。这是我第一次尝试使用MongoDB。怎么了?

1 个答案:

答案 0 :(得分:0)

尝试在没有b

的情况下运行mongod.exe

https://docs.mongodb.org/manual/reference/program/mongod/#bin.mongod

相关问题