我在一个项目中使用Meteor。如何使用可选参数在mongodb中进行查询?
答案 0 :(得分:0)
以下是基于表单中的值构建选择器的简单示例:
var firstName = $.trim($('#first-name').val());
var lastName = $.trim($('#last-name').val());
var selector = {};
if (firstName)
selector['profile.firstName'] = firstName;
if (lastName)
selector['profile.lastName'] = lastName;
Meteor.users.find(selector);