zoukankan      html  css  js  c++  java
  • mongodb 遇到问题-查询单个需要包装id

    mongodb,get字符查询需要传入特定的包装id才能识别

     1 const ObjectID = require('mongodb').ObjectID
     2 
     3 exports.queryOne = (req, res) => {
     4     console.log(req.body)
     5     MongoClient.connect(url, function(err, client) {
     6             assert.equal(null, err);
     7             const db = client.db(dbName);
     8             // Get the documents collection
     9             const collection = db.collection('documents');
    10             const id = new ObjectID(req.params.id)
    11             console.log(id)
    12             // Find some documents
    13             collection.find({'_id':id}).toArray(function(err, docs) {
    14                 assert.equal(err, null);
    15                 res.status(200).json(docs)
    16                 client.close();
    17             });
    18         });
    19     }
    学习记录,望指点学习,谢谢!
  • 相关阅读:
    八、分组
    七、select使用
    六、SQL基础应用
    五、修改MySQL密码
    side Effect
    js函数式编程
    React生命周期
    Portals
    git使用技巧
    函数式编程
  • 原文地址:https://www.cnblogs.com/herewego/p/9280052.html
Copyright © 2011-2022 走看看