Meteor find()没有按预期工作

时间:2017-09-18 13:27:02

标签: javascript node.js mongodb meteor

当我使用Requests.find().fetch()函数而没有任何参数时,它会返回集合中的所有文档。以下是其中两份文件:

[ { _id: { _str: '594a50a9c20c271100f35609' },
I20170918-17:09:04.224(4)?     hospital: 'Kholah',
I20170918-17:09:04.224(4)?     state: 'Muscat',
I20170918-17:09:04.224(4)?     reasons: 'From Android\ndafaf\nad\nasdasda\nfa\nd',
I20170918-17:09:04.224(4)?     requestedDateTime: '27-6-2017 16:55',
I20170918-17:09:04.225(4)?     requestNumber: '123456',
I20170918-17:09:04.225(4)?     status: 'Pending',
I20170918-17:09:04.225(4)?     __v: 0 },
I20170918-17:09:04.225(4)?   { _id: { _str: '594a512dc20c271100f3560a' },
I20170918-17:09:04.225(4)?     hospital: 'second',
I20170918-17:09:04.225(4)?     state: 'Sohar',
I20170918-17:09:04.225(4)?     reasons: 'From IPhone\n\nFdsfsdf\nDfsfsdf\n\nFsfsd',
I20170918-17:09:04.225(4)?     requestedDateTime: 'June 23, 2017 at 8:58 AM',
I20170918-17:09:04.226(4)?     requestNumber: '111111',
I20170918-17:09:04.226(4)?     status: 'Pending',
I20170918-17:09:04.226(4)?     __v: 0 },

以下是我在服务器中运行的代码:

Meteor.publish('currentRequest', function (requestId) {
        console.log(requestId) // prints the item  _id successfully
        console.log(Requests.find({ '_id._str': requestId}).fetch()) // prints "[]" in the terminal
        return Requests.find({'_id._str': requestId}).fetch();
    });

当我尝试console.log(Requests.find({ state: 'Sohar'}).fetch()) 时,它会成功打印文档。但我想根据他们的_id返回文件,我该如何实现呢?

修改 我将_id格式从string格式更改为ObjectID("")格式,我仍然得到空数组,如下所示

=> Meteor server restarted                    
I20170918-18:11:53.556(4)? ObjectID("594a50a9c20c271100f35609")
I20170918-18:11:53.804(4)? []

0 个答案:

没有答案
相关问题