java - 如何在 Java 中使用 DBCursor 获取数值?
问题描述
我正在使用 Java 和 MongoDB 从文档中检索结果。我想从 imdb.rating 中获取一个数值,但似乎找不到解决方案。我可以将它作为字符串获取,然后解析该值,但它也会包含 '$numberDouble' 部分,这会给我带来问题。
文档片段:
{
"_id": {
"$oid": "573a1390f29313caabcd42e8"
},
"plot": "A group of bandits stage a brazen train hold-up, only to find a determined posse hot on their heels.",
"genres": [
"Short",
"Western"
],
"runtime": 11,
"cast": [
"A.C. Abadie",
"Gilbert M. 'Broncho Billy' Anderson",
"George Barnes",
"Justus D. Barnes"
],
"poster": "https://m.media-amazon.com/images/M/MV5BMTU3NjE5NzYtYTYyNS00MDVmLWIwYjgtMmYwYWIxZDYyNzU2XkEyXkFqcGdeQXVyNzQzNzQxNzI@._V1_SY1000_SX677_AL_.jpg",
"title": "The Great Train Robbery",
"fullplot": "Among the earliest existing films in American cinema - notable as the first film that presented a narrative story to tell - it depicts a group of cowboy outlaws who hold up a train and rob the passengers. They are then pursued by a Sheriff's posse. Several scenes have color included - all hand tinted.",
"languages": [
"English"
],
"released": {
"$date": "1903-12-01T00:00:00.000Z"
},
"directors": [
"Edwin S. Porter"
],
"rated": "TV-G",
"awards": {
"wins": 1,
"nominations": 0,
"text": "1 win."
},
"lastupdated": "2015-08-13 00:27:59.177000000",
"year": 1903,
"imdb": {
"rating": {
"$numberDouble": "7.4"
},
"votes": 9847,
"id": 439
},
"countries": [
"USA"
],
"type": "movie",
"tomatoes": {
"viewer": {
"rating": {
"$numberDouble": "3.7"
},
"numReviews": 2559,
"meter": 75
},
"fresh": 6,
"critic": {
"rating": {
"$numberDouble": "7.6"
},
"numReviews": 6,
"meter": 100
},
"rotten": 0,
"lastUpdated": {
"$date": "2015-08-08T19:16:10.000Z"
}
}
}
解决方案
推荐阅读
- yaml - 每个 bash 步骤是否都会创建一个新的 shell 环境?
- nginx - 如何在 nginx 中选择解析器?
- java - OpenGL Compute Shader 未在笔记本电脑上链接
- reactjs - 增量更新状态数组,而不是完全更新
- c++ - 在 C++ 中组合字符串以重命名文件以显示日期
- python - 用于文本分类的 SkLearn 模型
- python - 将文件导入python
- html - 如何在 MVC 5 视图中使用 jQuery 为绑定到模型的 Html.TextBoxFor 字段设置值
- pine-script - 使用具有可变长度的 percentile_nearest_rank 计算运行中位数
- swift - 无法将 Firestore 数据保存到全局结构中