我应该使用什么 "Logical Query Operator/s" 来合并两个单独的查询?
What "Logical Query Operator/s" should I use to merge two separate queries?
我使用什么逻辑查询Operator/s来连接两个查询生成属于 登录用户 Meteor.userId();
AND 的所有文档 登录用户 [= recipientNumber
变量中 75=] 的 phone 数字。
文档在 recipientNumber
变量中包含 logged in users phone 编号,表明 logged in user[=75] =] 是资金接收人。
作为参考,在下面找到 登录用户 的详细信息:
var user = Meteor.userId();
var userDetails = Meteor.users.findOne({_id: user}, { fields: { "profile.telephoneNumber": 1, "profile.name": 1 } } );
var usersNumber = userDetails.profile.telephoneNumber;
var userName = userDetails.profile.name;
console.log("Users _id is: " +user);
console.log("Users Number is: " +usersNumber);
console.log("Users Name is: " +userName);
上面的代码正确产生:
Users _id is: "sxY3fsY9LmJYqFkiG"
Users Number is: +254705086633
Users Name is: Sir.BT
recipientsDetails.find({ }).fetch();
显示主题中的集合内容:
0:
payersName: "The LucidOreo"
payersUserId: "KDJFGkCRF3E5nY37e"
recipientNumber: "+254705086633"
_id: "MMyinrcrrYpz2haxq"
1:
payersName: "Sir.BT"
payersUserId: "sxY3fsY9LmJYqFkiG"
recipientNumber: "+254705086633"
_id: "YbPFT9ecCA4FTgqsn"
2:
payersName: "Sir.BT"
payersUserId: "sxY3fsY9LmJYqFkiG"
recipientNumber: "+254705577633"
_id: "ZPWNsQ7TWSJcERSJv"
下面的查询过滤集合,根据用户 Meteor.userId() 仅显示属于该用户的文档: sxY3fsY9LmJYqFkiG.
var user = Meteor.userId();
recipientsDetails.find( {payersUserId: user} ).fetch();
查找以下结果:
0:
payersName: "Sir.BT"
payersUserId: "sxY3fsY9LmJYqFkiG"
recipientNumber: "+254705086633"
_id: "YbPFT9ecCA4FTgqsn"
1:
payersName: "Sir.BT"
payersUserId: "sxY3fsY9LmJYqFkiG"
recipientNumber: "+254705577633"
_id: "ZPWNsQ7TWSJcERSJv"
我想制定一个查询来显示 两个 事物的组合:
属于登录用户的所有文档(如下代码所示):
var user = Meteor.userId();
recipientsDetails.find( {payersUserId: user} ).fetch();
...以及所有带有登录用户 phone 编号的文档(也如下面的代码所示):
var user = Meteor.userId();
var userDetails = Meteor.users.findOne({_id: user}, { fields {"profile.telephoneNumber": 1 } } );
var usersNumber = userDetails.profile.telephoneNumber;
recipientsDetails.find( {recipientNumber: usersNumber} ).fetch();
我应该在查询中使用什么逻辑查询 Operator/s 来产生这个?
我试过了:
var user = Meteor.userId();
var userDetails = Meteor.users.findOne({_id: user}, { fields: { "profile.telephoneNumber": 1 } } );
var usersNumber = userDetails.profile.telephoneNumber;
recipientsDetails.find( { $and: [{payersUserId: user}, {recipientNumber: usersNumber } ] } ).fetch();
不幸的是,这会错误地产生:
0:
payersName: "Sir.BT"
payersUserId: "sxY3fsY9LmJYqFkiG"
recipientNumber: "+254705086633"
_id: "YbPFT9ecCA4FTgqsn"
1:
payersName: "Sir.BT"
payersUserId: "sxY3fsY9LmJYqFkiG"
recipientNumber: "+254705577633"
_id: "ZPWNsQ7TWSJcERSJv"
...并遗漏:
payersName: "The LucidOreo"
payersUserId: "KDJFGkCRF3E5nY37e"
recipientNumber: "+254705086633"
_id: "MMyinrcrrYpz2haxq"
...其中清楚地带有 recipientNumber: "+254705086633"
登录用户 号码。
澄清一下,所需的产量为:
0:
payersName: "The LucidOreo"
payersUserId: "KDJFGkCRF3E5nY37e"
recipientNumber: "+254705086633"
_id: "MMyinrcrrYpz2haxq"
1:
payersName: "Sir.BT"
payersUserId: "sxY3fsY9LmJYqFkiG"
recipientNumber: "+254705086633"
_id: "YbPFT9ecCA4FTgqsn"
2:
payersName: "Sir.BT"
payersUserId: "sxY3fsY9LmJYqFkiG"
recipientNumber: "+254705577633"
_id: "ZPWNsQ7TWSJcERSJv"
任何人都可以向我解释为什么遗漏了这一点以及如何更好地制定主题中的查询吗?
我相信如果您替换以下内容应该可以工作:
recipientsDetails.find( { $and: [{payersUserId: user}, {recipientNumber: usersNumber } ] } ).fetch();
和
recipientsDetails.find( { $or: [{payersUserId: user}, {recipientNumber: usersNumber } ] } ).fetch();
我使用什么逻辑查询Operator/s来连接两个查询生成属于 登录用户 Meteor.userId();
AND 的所有文档 登录用户 [= recipientNumber
变量中 75=] 的 phone 数字。
文档在 recipientNumber
变量中包含 logged in users phone 编号,表明 logged in user[=75] =] 是资金接收人。
作为参考,在下面找到 登录用户 的详细信息:
var user = Meteor.userId();
var userDetails = Meteor.users.findOne({_id: user}, { fields: { "profile.telephoneNumber": 1, "profile.name": 1 } } );
var usersNumber = userDetails.profile.telephoneNumber;
var userName = userDetails.profile.name;
console.log("Users _id is: " +user);
console.log("Users Number is: " +usersNumber);
console.log("Users Name is: " +userName);
上面的代码正确产生:
Users _id is: "sxY3fsY9LmJYqFkiG"
Users Number is: +254705086633
Users Name is: Sir.BT
recipientsDetails.find({ }).fetch();
显示主题中的集合内容:
0:
payersName: "The LucidOreo"
payersUserId: "KDJFGkCRF3E5nY37e"
recipientNumber: "+254705086633"
_id: "MMyinrcrrYpz2haxq"
1:
payersName: "Sir.BT"
payersUserId: "sxY3fsY9LmJYqFkiG"
recipientNumber: "+254705086633"
_id: "YbPFT9ecCA4FTgqsn"
2:
payersName: "Sir.BT"
payersUserId: "sxY3fsY9LmJYqFkiG"
recipientNumber: "+254705577633"
_id: "ZPWNsQ7TWSJcERSJv"
下面的查询过滤集合,根据用户 Meteor.userId() 仅显示属于该用户的文档: sxY3fsY9LmJYqFkiG.
var user = Meteor.userId();
recipientsDetails.find( {payersUserId: user} ).fetch();
查找以下结果:
0:
payersName: "Sir.BT"
payersUserId: "sxY3fsY9LmJYqFkiG"
recipientNumber: "+254705086633"
_id: "YbPFT9ecCA4FTgqsn"
1:
payersName: "Sir.BT"
payersUserId: "sxY3fsY9LmJYqFkiG"
recipientNumber: "+254705577633"
_id: "ZPWNsQ7TWSJcERSJv"
我想制定一个查询来显示 两个 事物的组合:
属于登录用户的所有文档(如下代码所示):
var user = Meteor.userId();
recipientsDetails.find( {payersUserId: user} ).fetch();
...以及所有带有登录用户 phone 编号的文档(也如下面的代码所示):
var user = Meteor.userId();
var userDetails = Meteor.users.findOne({_id: user}, { fields {"profile.telephoneNumber": 1 } } );
var usersNumber = userDetails.profile.telephoneNumber;
recipientsDetails.find( {recipientNumber: usersNumber} ).fetch();
我应该在查询中使用什么逻辑查询 Operator/s 来产生这个?
我试过了:
var user = Meteor.userId();
var userDetails = Meteor.users.findOne({_id: user}, { fields: { "profile.telephoneNumber": 1 } } );
var usersNumber = userDetails.profile.telephoneNumber;
recipientsDetails.find( { $and: [{payersUserId: user}, {recipientNumber: usersNumber } ] } ).fetch();
不幸的是,这会错误地产生:
0:
payersName: "Sir.BT"
payersUserId: "sxY3fsY9LmJYqFkiG"
recipientNumber: "+254705086633"
_id: "YbPFT9ecCA4FTgqsn"
1:
payersName: "Sir.BT"
payersUserId: "sxY3fsY9LmJYqFkiG"
recipientNumber: "+254705577633"
_id: "ZPWNsQ7TWSJcERSJv"
...并遗漏:
payersName: "The LucidOreo"
payersUserId: "KDJFGkCRF3E5nY37e"
recipientNumber: "+254705086633"
_id: "MMyinrcrrYpz2haxq"
...其中清楚地带有 recipientNumber: "+254705086633"
登录用户 号码。
澄清一下,所需的产量为:
0:
payersName: "The LucidOreo"
payersUserId: "KDJFGkCRF3E5nY37e"
recipientNumber: "+254705086633"
_id: "MMyinrcrrYpz2haxq"
1:
payersName: "Sir.BT"
payersUserId: "sxY3fsY9LmJYqFkiG"
recipientNumber: "+254705086633"
_id: "YbPFT9ecCA4FTgqsn"
2:
payersName: "Sir.BT"
payersUserId: "sxY3fsY9LmJYqFkiG"
recipientNumber: "+254705577633"
_id: "ZPWNsQ7TWSJcERSJv"
任何人都可以向我解释为什么遗漏了这一点以及如何更好地制定主题中的查询吗?
我相信如果您替换以下内容应该可以工作:
recipientsDetails.find( { $and: [{payersUserId: user}, {recipientNumber: usersNumber } ] } ).fetch();
和
recipientsDetails.find( { $or: [{payersUserId: user}, {recipientNumber: usersNumber } ] } ).fetch();