You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add documentation for count, getCollections, DropCollection, and CollectionStats.
Fixed a couple of typos.
Added tests for drop collections combined with getCollections, and also a test for CollectionStats
Copy file name to clipboardExpand all lines: README.md
+209-32
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,9 @@
1
1
# MongoDB Persistor
2
2
3
-
This module allows data to be saved, retrieved, searched for, and deleted in a MongoDB instance. MongoDB is a great match for persisting vert.x data since it natively handles JSON (BSON) documents. To use this module you must have a MongoDB instance running on your network.
3
+
This module allows data to be saved, retrieved, searched for, and deleted in a MongoDB instance. MongoDB is a great match
4
+
for persisting vert.x data since it natively handles JSON (BSON) documents.
5
+
6
+
####To use this module you must have a MongoDB instance running on your network.
4
7
5
8
This is a multi-threaded worker module.
6
9
@@ -84,7 +87,7 @@ When the save complete successfully, a reply message is sent back to the sender
84
87
"status": "ok"
85
88
}
86
89
87
-
The reply will also contain a field `_id` if the document that was saved didn't specifiy an id, this will be an automatically generated UUID, for example:
90
+
The reply will also contain a field `_id` if the document that was saved didn't specify an id, this will be an automatically generated UUID, for example:
88
91
89
92
{
90
93
"status": "ok"
@@ -100,7 +103,8 @@ If an error occurs in saving the document a reply is returned:
100
103
"message": <message>
101
104
}
102
105
103
-
Where `message` is an error message.
106
+
Where
107
+
*`message` is an error message.
104
108
105
109
106
110
### Update
@@ -168,7 +172,7 @@ To find documents send a JSON message to the module main address:
168
172
169
173
Where:
170
174
*`collection` is the name of the MongoDB collection that you wish to search in in. This field is mandatory.
171
-
*`matcher` is a JSON object that you want to match against to find matching documents. This obeys the normal MongoDB matching rues.
175
+
*`matcher` is a JSON object that you want to match against to find matching documents. This obeys the normal MongoDB matching rules.
172
176
*`sort_query` provides an order for sorting the responses that you are returned.
173
177
*`keys` is an optional JSON object that contains the fields that should be returned for matched documents. See MongoDB manual for more information. Example: { "name": 1 } will only return objects with _id and the name field
174
178
*`skip` is a number which determines the number of documents to skip. This is optional. By default no documents are skipped.
@@ -194,7 +198,8 @@ When the find complete successfully, a reply message is sent back to the sender
194
198
"results": <results>
195
199
}
196
200
197
-
Where `results` is a JSON array containing the results of the find operation. For example:
201
+
Where
202
+
*`results` is a JSON array containing the results of the find operation. For example:
198
203
199
204
{
200
205
"status": "ok",
@@ -224,7 +229,8 @@ If an error occurs in finding the documents a reply is returned:
224
229
"message": <message>
225
230
}
226
231
227
-
Where `message` is an error message.
232
+
Where
233
+
*`message` is an error message.
228
234
229
235
If you would like to paginate your result :
230
236
@@ -243,26 +249,6 @@ Equivalence in mongoDB:
243
249
244
250
db.order.find().skip(10).limit(10)
245
251
246
-
### Count
247
-
248
-
Count all matching document in the database.
249
-
250
-
To count a document send a JSON message to the module main address:
251
-
252
-
{
253
-
"action": "count",
254
-
"collection": <collection>,
255
-
"matcher": <matcher>
256
-
}
257
-
258
-
When the count complete successfully, a reply message is sent back to the sender with the following data:
259
-
260
-
{
261
-
"status": "ok",
262
-
"count" : <number>
263
-
}
264
-
265
-
266
252
#### Batching
267
253
268
254
If a find returns many documents we do not want to load them all up into memory at once and send them in a single JSON message since this could result in the server running out of RAM.
@@ -315,7 +301,7 @@ To find a document send a JSON message to the module main address:
315
301
316
302
Where:
317
303
*`collection` is the name of the MongoDB collection that you wish to search in in. This field is mandatory.
318
-
*`matcher` is a JSON object that you want to match against to find a matching document. This obeys the normal MongoDB matching rues.
304
+
*`matcher` is a JSON object that you want to match against to find a matching document. This obeys the normal MongoDB matching rules.
319
305
*`keys` is an optional JSON object that contains the fields that should be returned for matched documents. See MongoDB manual for more information. Example: { "name": 1 } will only return objects with _id and the name field
320
306
321
307
If more than one document matches, just the first one will be returned.
@@ -346,7 +332,56 @@ If an error occurs in finding the documents a reply is returned:
346
332
"message": <message>
347
333
}
348
334
349
-
Where `message` is an error message.
335
+
Where
336
+
*`message` is an error message.
337
+
338
+
### Count
339
+
340
+
Counts the number of documents within a collection:
341
+
342
+
{
343
+
"action": "count",
344
+
"collection": <collection>,
345
+
"matcher": <matcher>
346
+
}
347
+
348
+
Where:
349
+
*`collection` is the name of the MongoDB collection that you wish to delete from. This field is mandatory.
350
+
*`matcher` is a JSON object that you want to match against to count matching documents. This obeys the normal MongoDB matching rules.
351
+
352
+
All documents within the collection will be counted.
353
+
354
+
An example would be:
355
+
356
+
{
357
+
"action": "count",
358
+
"collection": "items",
359
+
"matcher": {
360
+
"active": true
361
+
}
362
+
}
363
+
364
+
This should return the count of all documents that have the attribute active set to true.
365
+
366
+
When the count completes successfully, a reply message is sent back to the sender with the following data:
367
+
368
+
{
369
+
"status": "ok",
370
+
"count": <count>
371
+
}
372
+
373
+
Where
374
+
*`count` is the number of documents in the collection that matched the matcher.
375
+
376
+
If an error occurs in finding the documents a reply is returned:
377
+
378
+
{
379
+
"status": "error",
380
+
"message": <message>
381
+
}
382
+
383
+
Where
384
+
*`message` is an error message.
350
385
351
386
### Delete
352
387
@@ -362,7 +397,7 @@ To delete documents send a JSON message to the module main address:
362
397
363
398
Where:
364
399
*`collection` is the name of the MongoDB collection that you wish to delete from. This field is mandatory.
365
-
*`matcher` is a JSON object that you want to match against to delete matching documents. This obeys the normal MongoDB matching rues.
400
+
*`matcher` is a JSON object that you want to match against to delete matching documents. This obeys the normal MongoDB matching rules.
366
401
367
402
All documents that match will be deleted.
368
403
@@ -385,7 +420,8 @@ When the find complete successfully, a reply message is sent back to the sender
385
420
"number": <number>
386
421
}
387
422
388
-
Where `number` is the number of documents deleted.
423
+
Where
424
+
*`number` is the number of documents deleted.
389
425
390
426
If an error occurs in finding the documents a reply is returned:
391
427
@@ -394,7 +430,148 @@ If an error occurs in finding the documents a reply is returned:
394
430
"message": <message>
395
431
}
396
432
397
-
Where `message` is an error message.
433
+
Where
434
+
*`message` is an error message.
435
+
436
+
### Get Collections List
437
+
438
+
Returns the list of collection names in the db:
439
+
440
+
{
441
+
"action": "getCollections"
442
+
}
443
+
444
+
All collections within the current db will be returned if they exist.
445
+
446
+
An example would be:
447
+
448
+
{
449
+
"action": "getCollections"
450
+
}
451
+
452
+
This should return the list of all collections within the db
453
+
454
+
When getCollections completes successfully, a reply message is sent back to the sender with the following data:
455
+
456
+
{
457
+
"status": "ok",
458
+
"collections": [
459
+
<listOfCollections>
460
+
]
461
+
}
462
+
463
+
Where
464
+
* <listOfCollections> is a list containing each collection name in the db.
465
+
466
+
If an error occurs in finding the documents a reply is returned:
467
+
468
+
{
469
+
"status": "error",
470
+
"message": <message>
471
+
}
472
+
473
+
Where
474
+
*`message` is an error message.
475
+
476
+
### DB stats
477
+
478
+
Returns statistics about the db:
479
+
480
+
{
481
+
"action": "collectionStats",
482
+
"collection": <collection>
483
+
}
484
+
485
+
Where:
486
+
*`collection` is the name of the MongoDB collection that you wish to get statistics on in the db. This field is mandatory.
487
+
488
+
An example would be:
489
+
490
+
{
491
+
"action": "collectionStats",
492
+
"collection": "items"
493
+
}
494
+
495
+
This will return the statistics for the items collection within the db.
496
+
497
+
When collectionStats completes successfully, a reply message is sent back to the sender with the following data:
498
+
499
+
{
500
+
"status": "ok",
501
+
"stats": {
502
+
"serverUsed":"localhost/127.0.0.1:27017",
503
+
"ns"": "test_coll.items",
504
+
"count": 1,
505
+
"size": 136,
506
+
"avgObjSize": 136.0,
507
+
"storageSize": 8192,
508
+
"numExtents": 1,
509
+
"nindexes": 1,
510
+
"lastExtentSize": 8192,
511
+
"paddingFactor": 1.0,
512
+
"systemFlags": 1,
513
+
"userFlags": 0,
514
+
"totalIndexSize": 8176,
515
+
"indexSizes": {
516
+
"_id_":8176
517
+
},
518
+
"ok":1.0
519
+
}
520
+
}
521
+
522
+
Instead of putting placeholders in the DOC here are almost all the real values from the test_client.js run which tests collectionStats
523
+
I did change the "ns" value to match the collection name in the sample above.
524
+
525
+
If an error occurs in finding the documents a reply is returned:
526
+
527
+
{
528
+
"status": "error",
529
+
"message": <message>
530
+
}
531
+
532
+
Where
533
+
*`message` is an error message.
534
+
535
+
### Drop Collection
536
+
537
+
Drops a collection from the db:
538
+
539
+
{
540
+
"action": "dropCollection",
541
+
"collection": <collection>
542
+
}
543
+
544
+
Where:
545
+
*`collection` is the name of the MongoDB collection that you wish to drop from the db. This field is mandatory.
546
+
547
+
The collection will be removed from the db. This means that all the documents within the collection are gone. Use with CARE
548
+
549
+
An example would be:
550
+
551
+
{
552
+
"action": "dropCollection",
553
+
"collection": "items"
554
+
}
555
+
556
+
This should return an "ok" response, but nothing else. Check out the test_client.js to see our test to make sure
557
+
that dropCollection works. We just then go retrieve the collection list to make sure the collection we dropped is not
558
+
in the collection list returned but "getCollections" action
559
+
560
+
When the drop completes successfully, a reply message is sent back to the sender with the following data:
561
+
562
+
{
563
+
"status": "ok",
564
+
}
565
+
566
+
If an error occurs in finding the documents a reply is returned:
567
+
568
+
{
569
+
"status": "error",
570
+
"message": <message>
571
+
}
572
+
573
+
Where
574
+
*`message` is an error message.
398
575
399
576
### Command
400
577
@@ -446,5 +623,5 @@ An example for delete would be
0 commit comments