1
+ import { ObjectId } from "../../mod.ts" ;
1
2
import {
2
3
MongoInvalidArgumentError ,
3
4
MongoServerError ,
@@ -6,10 +7,10 @@ import { CreateCollectionOptions } from "../../src/types.ts";
6
7
import { testWithClient , testWithTestDBClient } from "../common.ts" ;
7
8
import { assert , assertEquals , assertRejects , semver } from "../test.deps.ts" ;
8
9
9
- interface IUser {
10
+ interface User {
11
+ _id : string | ObjectId ;
10
12
username ?: string ;
11
13
password ?: string ;
12
- _id : string ;
13
14
uid ?: number ;
14
15
date ?: Date ;
15
16
}
@@ -23,7 +24,7 @@ testWithClient("testListCollectionNames", async (client) => {
23
24
} ) ;
24
25
25
26
testWithTestDBClient ( "testInsertOne" , async ( db ) => {
26
- const users = db . collection < IUser > ( "mongo_test_users" ) ;
27
+ const users = db . collection < User > ( "mongo_test_users" ) ;
27
28
const insertId = await users . insertOne ( {
28
29
username : "user1" ,
29
30
password : "pass1" ,
@@ -45,7 +46,7 @@ testWithTestDBClient("testInsertOne", async (db) => {
45
46
} ) ;
46
47
47
48
testWithTestDBClient ( "testUpsertOne" , async ( db ) => {
48
- const users = db . collection < IUser > ( "mongo_test_users" ) ;
49
+ const users = db . collection < User > ( "mongo_test_users" ) ;
49
50
await users . insertOne ( {
50
51
username : "user1" ,
51
52
password : "pass1" ,
@@ -78,7 +79,7 @@ testWithTestDBClient("testUpsertOne", async (db) => {
78
79
} ) ;
79
80
80
81
testWithTestDBClient ( "testInsertOneTwice" , async ( db ) => {
81
- const users = db . collection < IUser > ( "mongo_test_users" ) ;
82
+ const users = db . collection < User > ( "mongo_test_users" ) ;
82
83
await users . insertOne ( {
83
84
_id : "aaaaaaaaaaaaaaaaaaaaaaaa" ,
84
85
username : "user1" ,
@@ -89,15 +90,14 @@ testWithTestDBClient("testInsertOneTwice", async (db) => {
89
90
users . insertOne ( {
90
91
_id : "aaaaaaaaaaaaaaaaaaaaaaaa" ,
91
92
username : "user1" ,
92
- // deno-lint-ignore no-explicit-any
93
- } ) as any ,
94
- undefined ,
93
+ } ) ,
94
+ MongoServerError ,
95
95
"E11000" ,
96
96
) ;
97
97
} ) ;
98
98
99
99
testWithTestDBClient ( "testFindOne" , async ( db ) => {
100
- const users = db . collection < IUser > ( "mongo_test_users" ) ;
100
+ const users = db . collection < User > ( "mongo_test_users" ) ;
101
101
await users . insertOne ( {
102
102
username : "user1" ,
103
103
password : "pass1" ,
@@ -122,7 +122,7 @@ testWithTestDBClient("testFindOne", async (db) => {
122
122
} ) ;
123
123
124
124
testWithTestDBClient ( "testInsertMany" , async ( db ) => {
125
- const users = db . collection < IUser > ( "mongo_test_users" ) ;
125
+ const users = db . collection < User > ( "mongo_test_users" ) ;
126
126
const { insertedCount, insertedIds } = await users . insertMany ( [
127
127
{
128
128
username : "many" ,
@@ -171,7 +171,7 @@ testWithTestDBClient("testFindAndModify-delete", async (db) => {
171
171
} ) ;
172
172
173
173
testWithTestDBClient ( "test chain call for Find" , async ( db ) => {
174
- const users = db . collection < IUser > ( "mongo_test_users" ) ;
174
+ const users = db . collection < User > ( "mongo_test_users" ) ;
175
175
await users . insertMany ( [
176
176
{
177
177
username : "user1" ,
@@ -191,7 +191,7 @@ testWithTestDBClient("test chain call for Find", async (db) => {
191
191
} ) ;
192
192
193
193
testWithTestDBClient ( "testUpdateOne" , async ( db ) => {
194
- const users = db . collection < IUser > ( "mongo_test_users" ) ;
194
+ const users = db . collection < User > ( "mongo_test_users" ) ;
195
195
await users . insertOne ( {
196
196
username : "user1" ,
197
197
password : "pass1" ,
@@ -206,7 +206,7 @@ testWithTestDBClient("testUpdateOne", async (db) => {
206
206
} ) ;
207
207
208
208
testWithTestDBClient ( "testUpdateOne Error" , async ( db ) => { // TODO: move tesr errors to a new file
209
- const users = db . collection < IUser > ( "mongo_test_users" ) ;
209
+ const users = db . collection < User > ( "mongo_test_users" ) ;
210
210
await users . insertOne ( {
211
211
username : "user1" ,
212
212
password : "pass1" ,
@@ -220,7 +220,7 @@ testWithTestDBClient("testUpdateOne Error", async (db) => { // TODO: move tesr e
220
220
} ) ;
221
221
222
222
testWithTestDBClient ( "testUpdateOneWithUpsert" , async ( db ) => {
223
- const users = db . collection < IUser > ( "mongo_test_users" ) ;
223
+ const users = db . collection < User > ( "mongo_test_users" ) ;
224
224
await users . insertOne ( {
225
225
username : "user1" ,
226
226
password : "pass1" ,
@@ -236,7 +236,7 @@ testWithTestDBClient("testUpdateOneWithUpsert", async (db) => {
236
236
} ) ;
237
237
238
238
testWithTestDBClient ( "testReplaceOne" , async ( db ) => {
239
- const users = db . collection < IUser > ( "mongo_test_users" ) ;
239
+ const users = db . collection < User > ( "mongo_test_users" ) ;
240
240
await users . insertOne ( {
241
241
username : "user1" ,
242
242
password : "pass1" ,
@@ -254,7 +254,7 @@ testWithTestDBClient("testReplaceOne", async (db) => {
254
254
} ) ;
255
255
256
256
testWithTestDBClient ( "testDeleteOne" , async ( db ) => {
257
- const users = db . collection < IUser > ( "mongo_test_users" ) ;
257
+ const users = db . collection < User > ( "mongo_test_users" ) ;
258
258
await users . insertOne ( {
259
259
username : "user1" ,
260
260
password : "pass1" ,
@@ -264,7 +264,7 @@ testWithTestDBClient("testDeleteOne", async (db) => {
264
264
} ) ;
265
265
266
266
testWithTestDBClient ( "testFindOr" , async ( db ) => {
267
- const users = db . collection < IUser > ( "mongo_test_users" ) ;
267
+ const users = db . collection < User > ( "mongo_test_users" ) ;
268
268
await users . insertMany ( [
269
269
{
270
270
username : "user1" ,
@@ -289,7 +289,7 @@ testWithTestDBClient("testFindOr", async (db) => {
289
289
} ) ;
290
290
291
291
testWithTestDBClient ( "testFind" , async ( db ) => {
292
- const users = db . collection < IUser > ( "mongo_test_users" ) ;
292
+ const users = db . collection < User > ( "mongo_test_users" ) ;
293
293
await users . insertMany ( [
294
294
{
295
295
username : "user" ,
@@ -315,7 +315,7 @@ testWithTestDBClient("testFind", async (db) => {
315
315
} ) ;
316
316
317
317
testWithTestDBClient ( "test multiple queries at the same time" , async ( db ) => {
318
- const users = db . collection < IUser > ( "mongo_test_users" ) ;
318
+ const users = db . collection < User > ( "mongo_test_users" ) ;
319
319
await users . insertOne ( {
320
320
_id : "aaaaaaaaaaaaaaaaaaaaaaaa" ,
321
321
username : "user1" ,
@@ -335,7 +335,7 @@ testWithTestDBClient("test multiple queries at the same time", async (db) => {
335
335
} ) ;
336
336
337
337
testWithTestDBClient ( "testCount" , async ( db ) => {
338
- const users = db . collection < IUser > ( "mongo_test_users" ) ;
338
+ const users = db . collection < User > ( "mongo_test_users" ) ;
339
339
await users . insertMany ( [
340
340
{
341
341
username : "user" ,
@@ -355,7 +355,7 @@ testWithTestDBClient("testCount", async (db) => {
355
355
} ) ;
356
356
357
357
testWithTestDBClient ( "testCountDocuments" , async ( db ) => {
358
- const users = db . collection < IUser > ( "mongo_test_users" ) ;
358
+ const users = db . collection < User > ( "mongo_test_users" ) ;
359
359
await users . insertMany ( [
360
360
{
361
361
username : "user1" ,
@@ -382,7 +382,7 @@ testWithTestDBClient("testCountDocuments", async (db) => {
382
382
} ) ;
383
383
384
384
testWithTestDBClient ( "testEstimatedDocumentCount" , async ( db ) => {
385
- const users = db . collection < IUser > ( "mongo_test_users" ) ;
385
+ const users = db . collection < User > ( "mongo_test_users" ) ;
386
386
await users . insertMany ( [
387
387
{
388
388
username : "user1" ,
@@ -406,7 +406,7 @@ testWithTestDBClient("testEstimatedDocumentCount", async (db) => {
406
406
} ) ;
407
407
408
408
testWithTestDBClient ( "testAggregation" , async ( db ) => {
409
- const users = db . collection < IUser > ( "mongo_test_users" ) ;
409
+ const users = db . collection < User > ( "mongo_test_users" ) ;
410
410
await users . insertMany ( [
411
411
{
412
412
username : "user1" ,
@@ -426,7 +426,7 @@ testWithTestDBClient("testAggregation", async (db) => {
426
426
} ,
427
427
] ) ;
428
428
const docs = await users
429
- . aggregate ( [
429
+ . aggregate < { _id : string ; total : number } > ( [
430
430
{ $match : { username : "many" } } ,
431
431
{ $group : { _id : "$username" , total : { $sum : 1 } } } ,
432
432
] )
@@ -435,7 +435,7 @@ testWithTestDBClient("testAggregation", async (db) => {
435
435
} ) ;
436
436
437
437
testWithTestDBClient ( "testUpdateMany" , async ( db ) => {
438
- const users = db . collection < IUser > ( "mongo_test_users" ) ;
438
+ const users = db . collection < User > ( "mongo_test_users" ) ;
439
439
await users . insertMany ( [
440
440
{
441
441
username : "user1" ,
@@ -467,7 +467,7 @@ testWithTestDBClient("testUpdateMany", async (db) => {
467
467
} ) ;
468
468
469
469
testWithTestDBClient ( "testDeleteMany" , async ( db ) => {
470
- const users = db . collection < IUser > ( "mongo_test_users" ) ;
470
+ const users = db . collection < User > ( "mongo_test_users" ) ;
471
471
await users . insertMany ( [
472
472
{
473
473
username : "user1" ,
@@ -491,7 +491,7 @@ testWithTestDBClient("testDeleteMany", async (db) => {
491
491
} ) ;
492
492
493
493
testWithTestDBClient ( "testDistinct" , async ( db ) => {
494
- const users = db . collection < IUser > ( "mongo_test_users" ) ;
494
+ const users = db . collection < User > ( "mongo_test_users" ) ;
495
495
await users . insertMany ( [
496
496
{
497
497
username : "user1" ,
@@ -515,7 +515,7 @@ testWithTestDBClient("testDistinct", async (db) => {
515
515
} ) ;
516
516
517
517
testWithTestDBClient ( "testDropConnection" , async ( db ) => {
518
- const users = db . collection < IUser > ( "mongo_test_users" ) ;
518
+ const users = db . collection < User > ( "mongo_test_users" ) ;
519
519
await users . insertOne ( {
520
520
_id : "aaaaaaaaaaaaaaaaaaaaaaaa" ,
521
521
username : "user1" ,
@@ -526,7 +526,7 @@ testWithTestDBClient("testDropConnection", async (db) => {
526
526
} ) ;
527
527
528
528
testWithTestDBClient ( "testFindWithSort" , async ( db ) => {
529
- const users = db . collection < IUser > ( "mongo_test_users" ) ;
529
+ const users = db . collection < User > ( "mongo_test_users" ) ;
530
530
531
531
const condition = { uid : { $exists : true } } ;
532
532
@@ -565,7 +565,7 @@ testWithTestDBClient("testFindWithSort", async (db) => {
565
565
} ) ;
566
566
567
567
testWithTestDBClient ( "testFindEmptyAsyncIteration" , async ( db ) => {
568
- const users = db . collection < IUser > ( "mongo_test_users" ) ;
568
+ const users = db . collection < User > ( "mongo_test_users" ) ;
569
569
for ( let i = 0 ; i < 10 ; i ++ ) {
570
570
await users . insertOne ( {
571
571
username : "testFindWithSort" ,
@@ -591,7 +591,7 @@ testWithClient("testFindWithMaxTimeMS", async (client) => {
591
591
"4.2.0" ,
592
592
) ;
593
593
594
- const users = db . collection < IUser > ( "mongo_test_users" ) ;
594
+ const users = db . collection < User > ( "mongo_test_users" ) ;
595
595
for ( let i = 0 ; i < 10 ; i ++ ) {
596
596
await users . insertOne ( {
597
597
username : "testFindWithMaxTimeMS" ,
0 commit comments