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     }
学习记录,望指点学习,谢谢!
原文地址:https://www.cnblogs.com/herewego/p/9280052.html