Skip to content

Commit 9b403f1

Browse files
authored
Merge pull request #136 from hasezoey/removeOldQueryFn
Remove Functions / Options for Mongoose 7
2 parents a601c6c + cb7970a commit 9b403f1

File tree

6 files changed

+13
-536
lines changed

6 files changed

+13
-536
lines changed

README.md

Lines changed: 0 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,6 @@ const docs = await Artist().find(...).where(...);
5151
- [find()](#find)
5252
- [findOne()](#findone)
5353
- [count()](#count)
54-
- [remove()](#remove)
55-
- [update()](#update)
56-
- [the update document](#the-update-document)
57-
- [update() options](#update-options)
5854
- [findOneAndUpdate()](#findoneandupdate)
5955
- [findOneAndUpdate() options](#findoneandupdate-options)
6056
- [findOneAndRemove()](#findoneandremove)
@@ -102,7 +98,6 @@ const docs = await Artist().find(...).where(...);
10298
- [hint()](#hint)
10399
- [j()](#j)
104100
- [limit()](#limit)
105-
- [maxScan()](#maxscan)
106101
- [maxTime()](#maxtime)
107102
- [skip()](#skip)
108103
- [sort()](#sort)
@@ -114,7 +109,6 @@ const docs = await Artist().find(...).where(...);
114109
- [writeConcern()](#writeconcern)
115110
- [Write Concern:](#write-concern)
116111
- [slaveOk()](#slaveok)
117-
- [snapshot()](#snapshot)
118112
- [tailable()](#tailable)
119113
- [wtimeout()](#wtimeout)
120114
- [Helpers](#helpers-1)
@@ -187,99 +181,6 @@ const number = await mquery().count(match);
187181
console.log('we found %d matching documents', number);
188182
```
189183

190-
### remove()
191-
192-
Declares this query a _remove_ query. Optionally pass a match clause.
193-
194-
```js
195-
mquery().remove()
196-
mquery().remove(match)
197-
await mquery().remove()
198-
await mquery().remove(match)
199-
```
200-
201-
### update()
202-
203-
Declares this query an _update_ query. Optionally pass an update document, match clause, options.
204-
205-
```js
206-
mquery().update()
207-
mquery().update(match, updateDocument)
208-
mquery().update(match, updateDocument, options)
209-
210-
// the following all execute the command
211-
await mquery().update()
212-
await mquery().update({ $set: updateDocument })
213-
await mquery().update(match, updateDocument)
214-
await mquery().update(match, updateDocument, options)
215-
```
216-
217-
#### the update document
218-
219-
All paths passed that are not `$atomic` operations will become `$set` ops. For example:
220-
221-
```js
222-
await mquery(collection).where({ _id: id }).update({ title: 'words' })
223-
```
224-
225-
becomes
226-
227-
```js
228-
await collection.update({ _id: id }, { $set: { title: 'words' } })
229-
```
230-
231-
This behavior can be overridden using the `overwrite` option (see below).
232-
233-
#### update() options
234-
235-
Options are passed to the `setOptions()` method.
236-
237-
- overwrite
238-
239-
Passing an empty object `{ }` as the update document will result in a no-op unless the `overwrite` option is passed. Without the `overwrite` option, the update operation will be ignored and the promise resolved without sending the command to MongoDB to prevent accidently overwritting documents in the collection.
240-
241-
```js
242-
var q = mquery(collection).where({ _id: id }).setOptions({ overwrite: true });
243-
await q.update({ }); // overwrite with an empty doc
244-
```
245-
246-
The `overwrite` option isn't just for empty objects, it also provides a means to override the default `$set` conversion and send the update document as is.
247-
248-
```js
249-
// create a base query
250-
var base = mquery({ _id: 108 }).collection(collection).toConstructor();
251-
252-
const doc = await base().findOne();
253-
console.log(doc); // { _id: 108, name: 'cajon' })
254-
255-
await base().setOptions({ overwrite: true }).update({ changed: true });
256-
const doc2 = base.findOne();
257-
console.log(doc2); // { _id: 108, changed: true }) - the doc was overwritten
258-
```
259-
260-
- multi
261-
262-
Updates only modify a single document by default. To update multiple documents, set the `multi` option to `true`.
263-
264-
```js
265-
await mquery()
266-
.collection(coll)
267-
.update({ name: /^match/ }, { $addToSet: { arr: 4 }}, { multi: true })
268-
269-
// another way of doing it
270-
await mquery({ name: /^match/ })
271-
.collection(coll)
272-
.setOptions({ multi: true })
273-
.update({ $addToSet: { arr: 4 }})
274-
275-
// update multiple documents with an empty doc
276-
var q = mquery(collection).where({ name: /^match/ });
277-
q.setOptions({ multi: true, overwrite: true })
278-
q.update({ });
279-
const result = await q.update();
280-
console.log(result);
281-
```
282-
283184
### findOneAndUpdate()
284185

285186
Declares this query a _findAndModify_ with update query. Optionally pass a match clause, update document, options.
@@ -896,8 +797,6 @@ This option is only valid for operations that write to the database:
896797
- `deleteMany()`
897798
- `findOneAndDelete()`
898799
- `findOneAndUpdate()`
899-
- `remove()`
900-
- `update()`
901800
- `updateOne()`
902801
- `updateMany()`
903802

@@ -919,18 +818,6 @@ _Cannot be used with `distinct()`._
919818

920819
[MongoDB documentation](http://docs.mongodb.org/manual/reference/method/cursor.limit/)
921820

922-
### maxScan()
923-
924-
Specifies the maxScan option.
925-
926-
```js
927-
query.maxScan(100)
928-
```
929-
930-
_Cannot be used with `distinct()`._
931-
932-
[MongoDB documentation](http://docs.mongodb.org/manual/reference/operator/maxScan/)
933-
934821
### maxTime()
935822

936823
Specifies the maxTimeMS option.
@@ -1087,8 +974,6 @@ This option is only valid for operations that write to the database:
1087974
- `deleteMany()`
1088975
- `findOneAndDelete()`
1089976
- `findOneAndUpdate()`
1090-
- `remove()`
1091-
- `update()`
1092977
- `updateOne()`
1093978
- `updateMany()`
1094979

@@ -1130,20 +1015,6 @@ query.slaveOk(false)
11301015

11311016
[MongoDB documentation](http://docs.mongodb.org/manual/reference/method/rs.slaveOk/)
11321017

1133-
### snapshot()
1134-
1135-
Specifies this query as a snapshot query.
1136-
1137-
```js
1138-
mquery().snapshot() // true
1139-
mquery().snapshot(true)
1140-
mquery().snapshot(false)
1141-
```
1142-
1143-
_Cannot be used with `distinct()`._
1144-
1145-
[MongoDB documentation](http://docs.mongodb.org/manual/reference/operator/snapshot/)
1146-
11471018
### tailable()
11481019

11491020
Sets tailable option.
@@ -1169,8 +1040,6 @@ This option is only valid for operations that write to the database:
11691040
- `deleteMany()`
11701041
- `findOneAndDelete()`
11711042
- `findOneAndUpdate()`
1172-
- `remove()`
1173-
- `update()`
11741043
- `updateOne()`
11751044
- `updateMany()`
11761045

@@ -1240,11 +1109,9 @@ mquery().setOptions({ collection: coll, limit: 20 })
12401109
- [sort](#sort) *
12411110
- [limit](#limit) *
12421111
- [skip](#skip) *
1243-
- [maxScan](#maxscan) *
12441112
- [maxTime](#maxtime) *
12451113
- [batchSize](#batchsize) *
12461114
- [comment](#comment) *
1247-
- [snapshot](#snapshot) *
12481115
- [hint](#hint) *
12491116
- [collection](#collection): the collection to query against
12501117

lib/collection/collection.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@
77
const methods = [
88
'find',
99
'findOne',
10-
'update',
1110
'updateMany',
1211
'updateOne',
1312
'replaceOne',
14-
'remove',
1513
'count',
1614
'distinct',
1715
'findOneAndDelete',

lib/collection/node.js

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -45,22 +45,14 @@ class NodeCollection extends Collection {
4545
}
4646

4747
/**
48-
* update(match, update, options)
49-
*/
50-
async update(match, update, options) {
51-
// DEBUG: removal of "update" is handled by https://github.com/mongoosejs/mquery/pull/136
52-
return this.collection.update(match, update, options);
53-
}
54-
55-
/**
56-
* update(match, update, options)
48+
* updateMany(match, update, options)
5749
*/
5850
async updateMany(match, update, options) {
5951
return this.collection.updateMany(match, update, options);
6052
}
6153

6254
/**
63-
* update(match, update, options)
55+
* updateOne(match, update, options)
6456
*/
6557
async updateOne(match, update, options) {
6658
return this.collection.updateOne(match, update, options);
@@ -88,15 +80,7 @@ class NodeCollection extends Collection {
8880
}
8981

9082
/**
91-
* remove(match, options)
92-
*/
93-
async remove(match, options) {
94-
// DEBUG: removal of "remove" is handled by https://github.com/mongoosejs/mquery/pull/136
95-
return this.collection.deleteMany(match, options);
96-
}
97-
98-
/**
99-
* findOneAndDelete(match, options)
83+
* findOneAndDelete(match, options, function(err[, result])
10084
*/
10185
async findOneAndDelete(match, options) {
10286
return this.collection.findOneAndDelete(match, options);

0 commit comments

Comments
 (0)