使用现有字段作为 mongodb 中的 objectId 以使用节点和 express 创建 REST api?

Using existing fields as objectId in mongodb to create REST api with node and express?

我的 JSON 文件是:

 [
   {'name': name,
    'birthday': birthday,
    'telephone': telephone,
    'details': details},
   ....
 ]

我的应用程序将能够接受 namebirthdaytelephone 值,这三个值的组合对于每个实体来说都是唯一的。我希望根据这三个值检索一个实体,比如 http://localhost:8000/name?=mary&birthday?=19880902&telephone?=2234324567 将 return Mary 的 json 对象。

我正在查看有关使用 mongodb 和 nodejs 的可用示例,其中大多数建议使用 new BSON.ObjectID(id) 创建一个全新的 _id 字段并执行类似于 [=18] 的操作=] 找到 id。是否可以不创建单独的 id 字段?

尝试使用带有 (req, res) 参数的回调。见 here:

app.get('/', function(req, res) {
  var findCursor = Users.find({ 
    "name": req.query.name, 
    "birthday": req.query.birthday,  
    "telephone": req.query.telephone 
  });
  cursor.each(function(err, doc) {
    if (err) console.log("Oh no!");
    if (doc != null) {
      // Do stuff
      res.send('GET request to user page?');
    }
  } 
});