gpt4 book ai didi

node.js - 按名称的Mongodb请求呈现错误的数据

转载 作者:太空宇宙 更新时间:2023-11-04 01:19:48 25 4
gpt4 key购买 nike

我想设置一个GET by name请求,但是我没有想要该条目,而是得到了列表中的最后一个

这是我有关mongo的数据:

{
number: 1,
_id: "5df7f816d64d8dcd8e48bd48",
name: "INFRA-",
author: "Rebecca Topakian",
format: "A4",
pages: 40,
paper: "Papier Serio Nero",
printing: "Impression off set argent HUV",
copies: 600,
price: 20,
desc_fr: "A la recherche de corps en transe, dans un état d'abandon total à la danse et au simple plaisir d'être, j'ai cherché à agir en chasseur invisible. Pour cela, j'ai transformé un appareil numérique afin qu'il ne soit sensible qu'aux longueurs d’onde correspondant à l’infrarouge. J'utilise un éclairage du même type, agissant comme un flash invisible à l'œil humain. Les sujets se révèlent alors dans des moments d’abandon, loin d’une quelconque mise en scène, et offrent au regardeur des portraits de l’oubli de soi.",
desc_en: "In the series “Infra-”, I’m using a digital transformed camera – the low-pass filter on the sensor has been removed so the camera is sensible to infrared. In the complete night of dancing parties, I enlighten my subjects by using an infrared led panel, invisible to the human eye but visible to the camera, allowing me to act discreetly. The subjects then reveal themselves in moments of abandonment, far from any staging, and offer the viewer portraits of selflessness - «non-portraits».",
new: false
},


这是我的要求:

router.get('/books/:name', (req, res, next) => {
let name = req.params.name;
let value = req.params.value;
var query = {};
query[name] = value;
console.log(req.params);
const localdb = db.client.db(process.env.DB_NAME);
const collection = localdb.collection(process.env.COLL_BOOKS);
collection.findOne(query, function (err, docs) {
if (err) throw err
res.status(200).send(docs);
});
});


谢谢

最佳答案

我想name属性不是变量,
尝试这个:

router.get('/books/:name', (req, res, next) => {
let name = req.params.name;
var query = {};
query['name'] = name;
const localdb = db.client.db(process.env.DB_NAME);
const collection = localdb.collection(process.env.COLL_BOOKS);
collection.findOne(query, function (err, docs) {
if (err) throw err
res.status(200).send(docs);
});
});

您必须使用以下内容查询mongo:
{
name: 'TOTO'
}

关于node.js - 按名称的Mongodb请求呈现错误的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59734337/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com