这个查找查询是否出错,因为我输入的数字太大
Is this find query erroring because I am inputting too large of a number?
我正在尝试编写一个C++程序,该程序可以找到一个位置并读取其数据。我需要查询一个mongodb,我在其中存储有关每个文档中的位置的信息。
我已经创建了与数据库的连接,可以找到集合中的所有文档。当我尝试构建一个基于经度和长度匹配位置的 find(( 查询时,我收到错误:
ReadStationData.cc:109:64: error: narrowing conversion of ‘3.9400500000000001e+1’ from ‘double’ to ‘std::size_t {aka long unsigned int}’ inside { } [-Wnarrowing]
auto cursor = coll.find({{"lat" , 39.400500000000000966}});
我的代码:
#include <cstdlib>
#include <iostream>
#include <string>
#include <bsoncxx/builder/basic/document.hpp>
#include <bsoncxx/builder/stream/document.hpp>
#include <bsoncxx/builder/basic/kvp.hpp>
#include <bsoncxx/json.hpp>
#include <bsoncxx/stdx/make_unique.hpp>
#include <mongocxx/client.hpp>
#include <mongocxx/instance.hpp>
#include <mongocxx/logger.hpp>
#include <mongocxx/options/client.hpp>
#include <mongocxx/uri.hpp>
int main(int argc, char* argv[]) {
using bsoncxx::builder::basic::kvp;
using bsoncxx::builder::basic::make_document;
mongocxx::instance inst{bsoncxx::stdx::make_unique};
try {
const auto uri = mongocxx::uri{"mongodb://user:pswd@32.445.67.89/snowdb?authSource=admin"};
mongocxx::options::client client_options;
if (uri.ssl()) {
mongocxx::options::ssl ssl_options;
client_options.ssl_opts(ssl_options);
}
auto client = mongocxx::client{uri, client_options};
auto admin = client["admin"];
auto result = admin.run_command(make_document(kvp("isMaster", 1)));
std::cout << bsoncxx::to_json(result) << "n";
mongocxx::database db = client["snowdb"];
mongocxx::collection coll = db["Location"];
using bsoncxx::builder::basic::kvp;
using bsoncxx::builder::basic::make_array;
using bsoncxx::builder::basic::make_document;
auto cursor = coll.find({{"lat" , 39.400500000000000966}});
for (auto&& doc : cursor) {
std::cout << bsoncxx::to_json(doc) << std::endl;
}
}
数据的外观如下:
{ "_id" : { "$oid" : "5d02ea10f21300007c1b7274" },
"lat" : [ 41.0367999999999995 ],
"lon" : [ -105.12600000000000477 ], .....
这样做的问题是数据值在列表 [] 中,我没有用数组将值括起来,如下所示:
auto cursor=coll.find(make_document(kvp("lon", make_array(-105.12000000000000455))));
相关文章:
- 如果输入数字为负数,如何循环
- C++程序来查找输入数字的最小/最大值
- 如何接受可变的输入数字?
- cin.fail 在输入数字和字母时不起作用
- 如何在函数中输入数字以输出单词?
- 如果用户输入数字 <0,我如何停止" while loop "?
- C++:如果用户输入数字将其转换为单词,并且如果按回车键程序应退出,则使用开关大小写
- 如何使用正则表达式将输入数字格式化为字符串
- 当我运行我的程序时,即使"user"输入数字||C++ 绘画作业
- C 如何进行计数循环,该循环确定两个输入数字中的哪个是最低的,并且从那里计数
- 如何要求用户在类函数中输入数字
- 输入数字输入到if语句中
- 为什么 cin.fail() 在输入数字后跟字符时不返回 false?
- search用字符串列表输入数字(类似于t9字典)
- 试图创建一个函数来查找用户输入数字的斐波那契数
- 如何允许用户输入数字和运算符
- QTreeWidgetItem 可编辑仅允许输入数字
- 如何提示用户输入数字,直到他们选择奇数?C++
- 输入数字,直到输入 -1
- 编写一个程序,输入数字 1-12 并输出相应的月份