Node Mongo - 无法找到文件

时间:2017-11-25 17:00:32

标签: node.js mongodb mongodb-query nodes

我找不到文件了。我有一个具有这种结构的集合"registosORS"

  {
    "_id" : ObjectId("5a1959d75e0b410558e515be"),
    "sessao" : "1",
    "proprioResponsavel" : "on",
    "outroResponsavel" : "",
    "relacao" : "",
    "valorIndividualmente" : "1",
    "valorInterpessoal" : "1",
    "valorSocialmente" : "1",
    "valorGlobalmente" : "1",
    "cliente_id" : "5a1407c8099ca208e48170a5",
    "email" : "mgoncalves@psi.uminho.pt",
    "data" : 1511610839374
}

我希望找到cliente_id值的文档。

一切正常但当我进入"registosORS"集合查询时,结果为null

ClientesDAO.prototype.insereDadosOrs = function(dadosORS, date, callback){
    this._connection.open(function(err,mongoClient){
        mongoClient.collection('clientes', function(err,collection){
            collection.findOne({email:dadosORS.email}).then(function(result){

                    var cliente_id = result._id;
                    dadosORS.data = date;
                    mongoClient.collection('registosORS', function(err,collection)                        {
                    collection.insert(dadosORS);

                    dadosSessao = {
                        cliente: cliente_id,
                        data: dadosORS.data,
                        numero : dadosORS.sessao
                    }

我相信这是问题:

mongoClient.collection('registosORS', function(err,collection){
                        collection.findOne({cliente_id:client_id, data:dadosORS.data}).then(function(result){ 
                        console.log(result);

结果是null。我在哪里失败?

1 个答案:

答案 0 :(得分:0)

我想你在这里有一个拼写错误:cliente_id:client_id应该是cliente_id:cliente_id