-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathBSONRegExp.txt
106 lines (66 loc) · 1.96 KB
/
BSONRegExp.txt
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
.. _server-bsonRegExp-method:
============
BSONRegExp()
============
.. default-domain:: mongodb
.. contents:: On this page
:local:
:backlinks: none
:depth: 1
:class: singlecol
Definition
----------
Creates a new :ref:`BSON type <bson-types>` for a regular expression.
Syntax
------
``BSONRegExp`` has the following syntax:
.. method:: BSONRegExp("<pattern>, "<flags>")
.. list-table::
:header-rows: 1
:widths: 20 20 60
* - Parameter
- Type
- Description
* - ``pattern``
- string
- The regular expression pattern. You must not wrap the pattern
with delimiter characters.
* - ``flag``
- string
- The regular expression flags. Characters in this argument are
sorted alphabetically.
.. _bsonRegExp-examples:
Examples
--------
Insert a ``BSONRegExp()`` Object
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Use the ``BSONRegExp()`` constructor to create the BSON regular expression.
.. code-block:: javascript
var bsonRegExp = BSONRegExp("(?-i)AA_", "i")
Insert the object into the ``testbson`` collection.
.. code-block:: javascript
db.testbson.insertOne( { foo: bsonRegExp } )
Retrieve a ``BSONRegExp()`` Object
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Query the ``testbson`` collection for the inserted document.
.. code-block:: javascript
db.testbson.find( {}, {}, { bsonRegExp: true } )
You can see the binary BSON regular expressions stored in the collection.
.. code-block:: javascript
:copyable: false
[
{
_id: ObjectId('65e8ba8a4b3c33a76e6cacca'),
foo: BSONRegExp('(?-i)AA_', 'i')
}
]
If you set ``bsonRegExp`` to ``false``, ``mongosh`` returns an error:
.. io-code-block::
:copyable: true
.. input::
:language: javascript
db.testbson.find( {}, {}, { bsonRegExp: false })
.. output::
:language: javascript
Uncaught:
SyntaxError: Invalid regular expression: /(?-i)AA_/i: Invalid group