File: mongoc_matcher_t.rst

package info (click to toggle)
mongo-c-driver 1.17.6-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 37,256 kB
  • sloc: ansic: 152,613; javascript: 7,954; python: 3,259; sh: 138; makefile: 29; xml: 10
file content (91 lines) | stat: -rw-r--r-- 1,761 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
:man_page: mongoc_matcher_t

mongoc_matcher_t
================

Client-side document matching abstraction

Synopsis
--------

.. code-block:: c

  typedef struct _mongoc_matcher_t mongoc_matcher_t;

``mongoc_matcher_t`` provides a reduced-interface for client-side matching of BSON documents.

It can perform the basics such as $in, $nin, $eq, $neq, $gt, $gte, $lt, and $lte.

.. warning::

  ``mongoc_matcher_t`` does not currently support the full spectrum of query operations that the MongoDB server supports.

Deprecated
----------

.. warning::

  ``mongoc_matcher_t`` is deprecated and will be removed in version 2.0.

.. only:: html

  Functions
  ---------

  .. toctree::
    :titlesonly:
    :maxdepth: 1

    mongoc_matcher_destroy
    mongoc_matcher_match
    mongoc_matcher_new

Example
-------

.. code-block:: c
  :caption: Filter a sequence of BSON documents from STDIN based on a query

  #include <bson/bson.h>
  #include <mongoc/mongoc.h>
  #include <stdio.h>

  int
  main (int argc, char *argv[])
  {
     mongoc_matcher_t *matcher;
     bson_reader_t *reader;
     const bson_t *bson;
     bson_t *spec;
     char *str;
     int fd;

     mongoc_init ();

  #ifdef _WIN32
     fd = fileno (stdin);
  #else
     fd = STDIN_FILENO;
  #endif

     reader = bson_reader_new_from_fd (fd, false);

     spec = BCON_NEW ("hello", "world");
     matcher = mongoc_matcher_new (spec, NULL);

     while ((bson = bson_reader_read (reader, NULL))) {
        if (mongoc_matcher_match (matcher, bson)) {
           str = bson_as_canonical_extended_json (bson, NULL);
           printf ("%s\n", str);
           bson_free (str);
        }
     }

     bson_reader_destroy (reader);
     bson_destroy (spec);

     mongoc_cleanup ();

     return 0;
  }