Arrays 使用mongoclinet的节点Js rest服务

Arrays 使用mongoclinet的节点Js rest服务,arrays,node.js,mongodb,distinct,Arrays,Node.js,Mongodb,Distinct,我是一名初级开发人员,正在Azure上使用Node JS、Express和MongoDB开发REST服务。 在我开发的第一个rest服务中,我总是使用Mongoose进行开发,但现在我发现在Cosmos DB上使用Mongoose存在一些问题。 Cosmos DB连接节点js与MongoDb mongoclient配合使用。我已经创建了一个db.js文件: var mongoClient = require("mongodb").MongoClient; mongoClient.connect(

我是一名初级开发人员,正在Azure上使用Node JS、Express和MongoDB开发REST服务。 在我开发的第一个rest服务中,我总是使用Mongoose进行开发,但现在我发现在Cosmos DB上使用Mongoose存在一些问题。 Cosmos DB连接节点js与MongoDb mongoclient配合使用。我已经创建了一个db.js文件:

var mongoClient = require("mongodb").MongoClient;
mongoClient.connect("mongodb://dbname:xxxxxxxx@dbname.documents.azure.com:10255/?ssl=true", function (err, db) {
db.close();
});

module.exports = mongoClient;
我定义了一个模型:

var mongoClient = require('../config/db.js');


var ProfileSchema = mongoClient.Schema({
companyName: { type: String, required: true },
firstname: {type: String, required: true},
address: {type: String, required: true},
city: {type: String, required: true},
state: {type: String, required: false},
postalcode: {type: String, required: true},
country: {type: String, required: true},
telephone: {type: String, required: true},
email: {type: String, required: true}
});
mongoClient.model('Profile', ProfileSchema);

module.exports = mongoClient.model('Profile');
这是我的路由器:

var Profile = require('../models/Profile');


router.get('/profile', function(req,res){
Profile.find({}, (err, profile) => {
    if (err) {
        console.log(err);
        return res.status(400).send({ status: 'ko', data: {msg: err.message }});
    }
    res.status(200).send({status: 'ok', data: {msg: 'List', profile: profile}});
});
});
现在,当我尝试运行应用程序ai时,收到以下错误: 架构不是一个函数 我不知道我的代码是否正确? 我怎么能修理

谢谢
最好的

我想你是在混淆概念。 您试图做的是使用MongoClient创建MongoDB模式,而MongoClient不支持这一点。 请使用猫鼬:

MongoClient是MongoDB的基本驱动程序,我认为您不想直接使用它

此外,在模型文件中,您正在使用以下内容:

var mongoClient = require('../config/db.js');
我不知道您在db.js文件中有什么,但我认为您没有在那里实现自定义Schema()函数,这就是为什么会出现错误“mongoClient.Schema不是函数”。 要做到这一点,请避免直接使用MongoClient,并查看一些Mongoose教程