[英]Convert objectID or _id from MongoDB Stitch query to string and map it
I am able to query a MongoDB Stitch database, but I get different results.我可以查询 MongoDB Stitch 数据库,但我得到了不同的结果。
If I console log all my data, it appears like this (note the 'id: Uint8Array(12) [ 94, 67, 83, … ]'如果我控制台记录我所有的数据,它看起来像这样(注意 'id: Uint8Array(12) [ 94, 67, 83, … ]'
item.find().asArray()
.then(data => {
console.log("Found docs", data)
});
However if I query it as an array:但是,如果我将其作为数组查询:
// Find database documents
item.find({})
.toArray()
.then(xyz =>
this.setState({xyz})
)
Here is the data I receive, and state:这是我收到的数据,state:
{
"xyz": [
{
"_id": {
"id": "DataView(12)",
"get_inc": "",
"getInc": "",
"generate": "",
"generationTime": 1581470496,
"inspect": "toString"
},
"company": "AAA",
"url": "http://www.google.com",
"loc": "sac, ca",
"gender": "female",
"tags": "clothes"
},
"{_id: {…}, company: \"BBB\", gender: \"male\", loc: \"sf…}",
"{_id: {…}, company: \"ZZZ\", gender: \"male\", loc: \"oa…}"
]
}
I would like to grab the objectID (which should be something like "5e435320e45ce24954381c52") which appears to be a unique key of a "bsonType": "objectId" schema, and I assume I need it converted as a string (?), so I can map it and have it serve as a unique key for use later in a table ("Each child in a list should have a unique "key" prop.").我想获取 objectID(应该类似于“5e435320e45ce24954381c52”),它似乎是“bsonType”的唯一键:“objectId”模式,我假设我需要将它转换为字符串(?),所以我可以 map 它并让它作为一个唯一的键,供稍后在表中使用(“列表中的每个孩子都应该有一个唯一的“键”道具。”)。
Thanks!谢谢!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.