我插入了这样的数据
{“userid”:“manaf”,“DataValue”:{“$type”:“00”,“$binary”:“sampleBinaryData”},“timestamp”:1460718961132,“_id”:{“$oid”:“ 5710cd7194e5f57831eea91e”},“__v”:0}
我需要获取提供的数据 b/w 时间戳值。
我已经通过在 mongoDb 客户端控制台中使用以下命令来完成此操作。
db.sampleCollection.find({"timestamp": {"$gte":1460703944149, "$lt":1460703944683 },"userid": "manaf"})
但我不能在我的 c 程序中这样使用。
这是我的客户程序
#include <bson.h>
#include <mongoc.h>
#include <stdio.h>
int
main (int argc,
char *argv[])
{
mongoc_client_t *client;
mongoc_collection_t *collection;
mongoc_cursor_t *cursor;
const bson_t *doc;
bson_t *query;
char *str;
mongoc_init ();
client = mongoc_client_new ("mongodb://localhost:27017/");
collection = mongoc_client_get_collection (client, "sampledb", "sampleCollection");
query = bson_new ();
BSON_APPEND_UTF8 (query, "timestamp": {"$gte":1460703944149, "$lt":1460703944683 },"userid": "manaf");
cursor = mongoc_collection_find (collection, MONGOC_QUERY_NONE, 0, 0, 0, query, NULL, NULL);
printf("Started\n");
while (mongoc_cursor_next (cursor, &doc)) {
str = bson_as_json (doc, NULL);
printf ("%s\n", str);
bson_free (str);
}
bson_destroy (query);
mongoc_cursor_destroy (cursor);
mongoc_collection_destroy (collection);
mongoc_client_destroy (client);
mongoc_cleanup ();
return 0;
}
我有这样的错误
error: macro "BSON_APPEND_UTF8" passed 4 arguments, but takes just 3
BSON_APPEND_UTF8 (query, "timestamp": {"$gte":1460703944149, "$lt":1460703944683 },"userid": "manaf");
这个程序的实际问题是什么?