我在 ANSI C 代码中使用 mongoc 库。我是 mongoc API 的新手,在创建查询时遇到问题。以下代码抛出断言 src/bson/bcon.c:807: bcon_append_ctx_va: Assertion `ctx->n != 0' failed。有人可以帮忙吗?
bool is_point_near_road(LOCATION_ITEM* item)
{
bson_error_t error;
const bson_t *doc;
char *str;
query = BCON_NEW ("road_segment:", "{",
"$near:", "{",
"$geometry:", "{",
"type:", "Point", "coordinates:", "[",BCON_DOUBLE(27.9478454), ",", BCON_DOUBLE(65.6503487), "]",
"}", "$maxDistance:", BCON_INT32(500),
"}",
"}",
);
cursor = mongoc_collection_find(collection_query, MONGOC_QUERY_NONE, 0, 0, 0, query, NULL, NULL);
if (cursor == NULL)
{
printf ("Cursor is NULL");
}
while (mongoc_cursor_more (cursor) && mongoc_cursor_next (cursor, &doc)) {
str = bson_as_json (doc, NULL);
printf ("STR: %s\n", str);
bson_free (str);
}
if (mongoc_cursor_error (cursor, &error)) {
fprintf (stderr, "An error occurred: %s\n", error.message);
}
mongoc_cursor_destroy (cursor);
bson_destroy (query);
return true;
}