Mongoose无法使用Find命令验证字符串

时间:2015-07-03 10:44:07

标签: node.js mongodb mongoose

您好我正在mongoose做一个项目,我需要显示其值被映射到序列号为No的文档。我的逻辑如下

  var mongoose=require('mongoose');
  var login=mongoose.model('Login');

      login.find(req.body.SerialNo,function(err,data){
          if(err){
             res.json({
                success:false,
                error:err
             });
          return;      
          } else{
              res.json({
                success:true,
                data:data
             }); 
          return;      
          }
     });

但是当我在DHCP中使用序列号No =“1234”运行它时,我获得了存储在集合中的所有数据。有人可以告诉我,我在哪里弄错了。 Find命令对字符串不起作用吗?

DHCP中的输入如下

   {
      "SerialNo":"124" 
   }

输出得到

            {
 "success": true,
 "data":[
 {"_id": "55965663a1c8cc6833216966", "SerialNo": "123456789123456800000", "__v": 0, "CreatedAt": "2015-07-03T09:31:15.658Z"…},
 {"_id": "55965675a1c8cc6833216967", "SerialNo": "12", "__v": 0, "CreatedAt": "2015-07-03T09:31:33.411Z"…},
  {"_id": "5596567fa1c8cc6833216968", "SerialNo": "121234567891234", "__v": 0, "CreatedAt": "2015-07-03T09:31:43.181Z"…},
{"_id": "55965683a1c8cc6833216969", "SerialNo": "1212345678912342", "__v": 0, "CreatedAt": "2015-07-03T09:31:47.793Z"…},
{"_id": "55965688a1c8cc683321696a", "SerialNo": "12123456789123424", "__v": 0, "CreatedAt": "2015-07-03T09:31:52.201Z"…},
{"_id": "55965718a1c8cc683321696b", "SerialNo": "12123456789123424", "__v": 0, "CreatedAt": "2015-07-03T09:34:16.275Z"…},
{"_id": "5596576ea1c8cc683321696c", "SerialNo": "12", "__v": 0, "CreatedAt": "2015-07-03T09:35:42.419Z"…},
{"_id": "55965772a1c8cc683321696d", "SerialNo": "123", "__v": 0, "CreatedAt": "2015-07-03T09:35:46.758Z"…},
{"_id": "55965777a1c8cc683321696e", "SerialNo": "124", "__v": 0, "CreatedAt": "2015-07-03T09:35:51.069Z"…}
 ]}

预期产出

 "success": true,
 "data":[ {"_id": "55965777a1c8cc683321696e", "SerialNo": "124", "__v": 0, "CreatedAt": "2015-07-03T09:35:51.069Z"…}
 ]}

0 个答案:

没有答案