我试图让Mongoose给我一个集合,它在命令行中对Mongo客户端运行正常,例如:
MongoDB shell版本:3.2.16
连接到:测试
db.users;
test.users
db.collection.find();
{" _id" :ObjectId(" 5986483ddfdfdcbb0d23eb01")," id" :1," firstName" :" Andrew"," lastName" :" Greg","电子邮件" :" agreg@gmail.com" }
{" _id" :ObjectId(" 59864993dfdfdcbb0d23eb02")," id" :2," firstName" :" Greg"," lastName" :"史密斯","电子邮件" :" gsmith@protonmail.com" }
{" _id" :ObjectId(" 598649d5dfdfdcbb0d23eb03")," id" :3," firstName" :" Kim"," lastName" :" T","电子邮件" :" random@outlook.com" }
我当前的快递代码是:
import express from 'express';
import bodyParser from 'body-parser';
import {graphqlExpress, graphiqlExpress} from 'graphql-server-express';
import {makeExecutableSchema} from 'graphql-tools';
import mongoose from 'mongoose';
//import MongoClient from 'mongodb';
//import mysql from 'mysql';
mongoose.connect('mongodb://127.0.0.1/test');
const Schema = mongoose.Schema;
const userSchema = new Schema({
id: Number,
firstName: String,
lastName: String,
email: String
});
const db = mongoose.connection;
db.on('error', console.error.bind(console, 'Mongo Connection Error:'));
db.on('open', function(err, doc){
if(err)
throw err;
var userModel = mongoose.model('userModel', userSchema,'users');
userModel.find().then(function(err,doc){
if(err)
throw err;
console.log(doc);
});
});
什么都不返回:S,我在两台不同的服务器上试过这个,得到了相同的结果。我正在运行Ubuntu 17.04和Ubuntu 16.04(在我测试的远程服务器上),我已关闭AppArmor并确保在127.0.0.1端口127.0.0.1上设置bindIp。
我已经检查了我能想到的一切,或者有没有人有想法?