Merge pull request #32 from kalkronline/doc-update

update docs for $exists
pull/30/head
tex0l 2 years ago committed by GitHub
commit 1daad3379e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      API.md
  2. 10
      README.md
  3. 2
      lib/datastore.js
  4. 2
      test/model.test.js

@ -70,7 +70,7 @@ documents, arrays, arrays of subdocuments and to match a specific element of an
<li><code>$gt</code>, <code>$gte</code>: greater than, greater than or equal</li> <li><code>$gt</code>, <code>$gte</code>: greater than, greater than or equal</li>
<li><code>$in</code>: member of. <code>value</code> must be an array of values</li> <li><code>$in</code>: member of. <code>value</code> must be an array of values</li>
<li><code>$ne</code>, <code>$nin</code>: not equal, not a member of</li> <li><code>$ne</code>, <code>$nin</code>: not equal, not a member of</li>
<li><code>$stat</code>: checks whether the document posses the property <code>field</code>. <code>value</code> should be true or false</li> <li><code>$exists</code>: checks whether the document posses the property <code>field</code>. <code>value</code> should be true or false</li>
<li><code>$regex</code>: checks whether a string is matched by the regular expression. Contrary to MongoDB, the use of <li><code>$regex</code>: checks whether a string is matched by the regular expression. Contrary to MongoDB, the use of
<code>$options</code> with <code>$regex</code> is not supported, because it doesn't give you more power than regex flags. Basic <code>$options</code> with <code>$regex</code> is not supported, because it doesn't give you more power than regex flags. Basic
queries are more readable so only use the <code>$regex</code> operator when you need to use another operator with it</li> queries are more readable so only use the <code>$regex</code> operator when you need to use another operator with it</li>
@ -972,7 +972,7 @@ documents, arrays, arrays of subdocuments and to match a specific element of an
<li><code>$gt</code>, <code>$gte</code>: greater than, greater than or equal</li> <li><code>$gt</code>, <code>$gte</code>: greater than, greater than or equal</li>
<li><code>$in</code>: member of. <code>value</code> must be an array of values</li> <li><code>$in</code>: member of. <code>value</code> must be an array of values</li>
<li><code>$ne</code>, <code>$nin</code>: not equal, not a member of</li> <li><code>$ne</code>, <code>$nin</code>: not equal, not a member of</li>
<li><code>$stat</code>: checks whether the document posses the property <code>field</code>. <code>value</code> should be true or false</li> <li><code>$exists</code>: checks whether the document posses the property <code>field</code>. <code>value</code> should be true or false</li>
<li><code>$regex</code>: checks whether a string is matched by the regular expression. Contrary to MongoDB, the use of <li><code>$regex</code>: checks whether a string is matched by the regular expression. Contrary to MongoDB, the use of
<code>$options</code> with <code>$regex</code> is not supported, because it doesn't give you more power than regex flags. Basic <code>$options</code> with <code>$regex</code> is not supported, because it doesn't give you more power than regex flags. Basic
queries are more readable so only use the <code>$regex</code> operator when you need to use another operator with it</li> queries are more readable so only use the <code>$regex</code> operator when you need to use another operator with it</li>

@ -48,7 +48,7 @@ repository. It is generated by running `npm run generateDocs:markdown`.
* [Inserting documents](#inserting-documents) * [Inserting documents](#inserting-documents)
* [Finding documents](#finding-documents) * [Finding documents](#finding-documents)
* [Basic Querying](#basic-querying) * [Basic Querying](#basic-querying)
* [Operators ($lt, $lte, $gt, $gte, $in, $nin, $ne, $stat, $regex)](#operators-lt-lte-gt-gte-in-nin-ne-stat-regex) * [Operators ($lt, $lte, $gt, $gte, $in, $nin, $ne, $exists, $regex)](#operators-lt-lte-gt-gte-in-nin-ne-stat-regex)
* [Array fields](#array-fields) * [Array fields](#array-fields)
* [Logical operators $or, $and, $not, $where](#logical-operators-or-and-not-where) * [Logical operators $or, $and, $not, $where](#logical-operators-or-and-not-where)
* [Sorting and paginating](#sorting-and-paginating) * [Sorting and paginating](#sorting-and-paginating)
@ -262,7 +262,7 @@ const doc = await db.findOneAsync({ _id: 'id1' })
// If no document is found, doc is null // If no document is found, doc is null
``` ```
#### Operators ($lt, $lte, $gt, $gte, $in, $nin, $ne, $stat, $regex) #### Operators ($lt, $lte, $gt, $gte, $in, $nin, $ne, $exists, $regex)
The syntax is `{ field: { $op: value } }` where `$op` is any comparison The syntax is `{ field: { $op: value } }` where `$op` is any comparison
operator: operator:
@ -271,7 +271,7 @@ operator:
* `$gt`, `$gte`: greater than, greater than or equal * `$gt`, `$gte`: greater than, greater than or equal
* `$in`: member of. `value` must be an array of values * `$in`: member of. `value` must be an array of values
* `$ne`, `$nin`: not equal, not a member of * `$ne`, `$nin`: not equal, not a member of
* `$stat`: checks whether the document posses the property `field`. `value` * `$exists`: checks whether the document posses the property `field`. `value`
should be true or false should be true or false
* `$regex`: checks whether a string is matched by the regular expression. * `$regex`: checks whether a string is matched by the regular expression.
Contrary to MongoDB, the use of `$options` with `$regex` is not supported, Contrary to MongoDB, the use of `$options` with `$regex` is not supported,
@ -292,8 +292,8 @@ const docs = await db.findAsync({ planet: { $gt: 'Mercury' } })
const docs = await db.findAsync({ planet: { $in: ['Earth', 'Jupiter'] } }) const docs = await db.findAsync({ planet: { $in: ['Earth', 'Jupiter'] } })
// docs contains Earth and Jupiter // docs contains Earth and Jupiter
// Using $stat // Using $exists
const docs = await db.findAsync({ satellites: { $stat: true } }) const docs = await db.findAsync({ satellites: { $exists: true } })
// docs contains only Mars // docs contains only Mars
// Using $regex with another operator // Using $regex with another operator

@ -89,7 +89,7 @@ const { isDate, pick, filterIndexNames } = require('./utils.js')
* - `$gt`, `$gte`: greater than, greater than or equal * - `$gt`, `$gte`: greater than, greater than or equal
* - `$in`: member of. `value` must be an array of values * - `$in`: member of. `value` must be an array of values
* - `$ne`, `$nin`: not equal, not a member of * - `$ne`, `$nin`: not equal, not a member of
* - `$stat`: checks whether the document posses the property `field`. `value` should be true or false * - `$exists`: checks whether the document posses the property `field`. `value` should be true or false
* - `$regex`: checks whether a string is matched by the regular expression. Contrary to MongoDB, the use of * - `$regex`: checks whether a string is matched by the regular expression. Contrary to MongoDB, the use of
* `$options` with `$regex` is not supported, because it doesn't give you more power than regex flags. Basic * `$options` with `$regex` is not supported, because it doesn't give you more power than regex flags. Basic
* queries are more readable so only use the `$regex` operator when you need to use another operator with it * queries are more readable so only use the `$regex` operator when you need to use another operator with it

@ -1169,7 +1169,7 @@ describe('Model', function () {
}) })
// General behaviour is tested in the block about $lt. Here we just test operators work // General behaviour is tested in the block about $lt. Here we just test operators work
describe('Other comparison operators: $lte, $gt, $gte, $ne, $in, $stat', function () { describe('Other comparison operators: $lte, $gt, $gte, $ne, $in, $exists', function () {
it('$lte', function () { it('$lte', function () {
model.match({ a: 5 }, { a: { $lte: 6 } }).should.equal(true) model.match({ a: 5 }, { a: { $lte: 6 } }).should.equal(true)
model.match({ a: 5 }, { a: { $lte: 5 } }).should.equal(true) model.match({ a: 5 }, { a: { $lte: 5 } }).should.equal(true)

Loading…
Cancel
Save