Json 使用Mongodb 3.x语法查询数据库?

Json 使用Mongodb 3.x语法查询数据库?,json,node.js,mongodb,express,Json,Node.js,Mongodb,Express,我正在尝试使用查询{isActive:true}返回数据库中的所有文档。这是我的路线: const express = require('express'); const app = express(); const assert = require('assert'); const port = 4000; const fs = require('fs'); const MongoClient = require('mongodb').MongoClient; const url = "mon

我正在尝试使用查询{isActive:true}返回数据库中的所有文档。这是我的路线:

const express = require('express');
const app = express();
const assert = require('assert');
const port = 4000;
const fs = require('fs');
const MongoClient = require('mongodb').MongoClient;
const url = "mongodb://localhost:27017/iRateIt";
const mongoose = require("mongoose");
mongoose.Promise = global.Promise;
mongoose.connect("mongodb://localhost:27017/iRateIt");

app.use("/",(req,res) => {
    MongoClient.connect(url, function(err, client){
        assert.equal(null, err);
        console.log("Connected successfully to server");

        const db = client.db("IRateIt");
        findDocuments(db, function() {
            client.close();
          });

    const findDocuments = function(db, callback) {
        var query = {isActive: true};
        // Get the documents collection
        const collection = db.collection('professors');
        // Find some documents
        collection.find({}).toArray(function(err, docs) {
          assert.equal(err, null);
          console.log("Found the following records");
          console.log(docs);
          callback(docs);
        });
      }
}
我的日志如下:

Server running on port 4000
Connected successfully to server
Found the following records
[]
这意味着它什么也找不到。我的语法可能有问题,但我已经为此工作了很多天,找不到解决方案

提前谢谢

编辑:mongo shell日志

> use IRateIt
switched to db IRateIt
> show collections
> db.collection.find()
> db.professors.find()
> db.professors.findOne()
null
> 
再编辑2个日志

> use iRateIt
switched to db iRateIt
> show collections
professors
responses
users
> db.professors.find()
{ "_id" : ObjectId("5afb358a21e490324913a75a"), "firstname" : "1", "lastname" : "2", "isActive" : true, "email" : "3", "password" : "4", "confirmpassword" : "4", "__v" : 0 }
{ "_id" : ObjectId("5afb35a521e490324913a75b"), "firstname" : "2", "lastname" : "2", "isActive" : false, "email" : "3", "password" : "4", "confirmpassword" : "4", "__v" : 0 }
> 

查询没有带{}的结果意味着您通常指向错误的源。要么数据库实际上与您认为要选择的数据库不同,要么集合与您认为的不同。显示如何从mongo shell访问此数据。i、 e如何连接,将数据库更改为您试图在此处使用的数据库,并从集合中至少选择一个文档。让人有点困惑的是,为什么您要通过mongoose和MongoClient进行连接,但首先要解决的问题是您的数据实际在哪里。很可能它真的在测试数据库中。请不要截图。您的代码和数据是文本,因此您需要输入并包含文本。在你当前的声誉分数上,当你试图上传一张图片到你的帖子时,实际上会有一条消息告诉你这一点。另外,请在问题中说明任何细节。评论仅仅是为了通知那些要求你澄清的人,你实际上已经编辑了你的问题并包含了要求的详细信息。在发出查询之前,你是否使用了iRateIt?这就是为什么你被要求在你的问题中加入细节。有太多的东西我们无法从屏幕截图中分辨出来,使用GUI也会使事情复杂化。据我们所知,名字上可能有一个空格前导或尾随错误,但我们无法从截图中分辨出来。因此,为什么要使用外壳呢?这就是iRateIt。您的GUI显示一个小写的i。当你在做show dbs的时候,输入show dbs。天哪,我一直意识到问题是在原始代码中使用了小写的I。多么愚蠢的错误啊。谢谢你帮我抓住那个!