Performance Difference in Mongoose vs MongoDB Native Driver

{ 
_id: ObjectID,
subrecord: ObjectID // for reference, usual case in real DB
name: String,
job: String,
company: String
}

READ

findOne

Mongoose x 21.45 ops/sec ±6.11% (53 runs sampled)
MongoDB x 22.33 ops/sec ±6.47% (55 runs sampled)
The Query is {'name': 'bugwheels500000'}
Mongoose x 11.86 ops/sec ±6.05% (57 runs sampled)
MongoDB x 12.73 ops/sec ±1.59% (61 runs sampled)
Fastest is MongoDB
Query: {name: 'bugwheels94544', job: 'Useless'}
Mongoose x 1,929 ops/sec ±9.70% (66 runs sampled)
MongoDB x 4,269 ops/sec ±9.41% (70 runs sampled)
Query: {_id: ‘5a9cf6860acccf5de0cf948a’ }
Mongoose x 1,427 ops/sec ±9.62% (65 runs sampled)
MongoDB x 4,725 ops/sec ±18.34% (68 runs sampled)
Query: {name: {$text :{ $search: 'bugwheels500000'}}}

find

Mongoose x 2.24 ops/sec ±4.32% (15 runs sampled)
MongoDB x 2.25 ops/sec ±3.16% (16 runs sampled)
Query: {'name': 'bugwheels500000'}
Mongoose x 2,238 ops/sec ±10.68% (70 runs sampled) 
MongoDB x 4,907 ops/sec ±9.31% (70 runs sampled)
Query: {_id: '5a9cf6860acccf5de0cf948a' }
Mongoose x 1,427 ops/sec ±9.62% (65 runs sampled)
MongoDB x 4,725 ops/sec ±18.34% (68 runs sampled)
Query: {name: {$text :{ $search: 'bugwheels500000'}}}

CREATE

Creating records is also very common operation so let’s look into this too. I will insert the following documents in following benchmarks

{
name: 'bugwheels',
interest: 'Not Many',
job: 'Useless'
}

insert

Insert will only insert one record at one time. Looks like there is negligible difference between insertion whether any additional index is set or not

Mongoose x 1,004 ops/sec ±19.87% (64 runs sampled)
MongoDB x 2,589 ops/sec ±8.24% (66 runs sampled)
Mongoose x 1,053 ops/sec ±7.50% (71 runs sampled)
MongoDB x 2,452 ops/sec ±8.98% (63 runs sampled)

insertMany

Mongoose x 118 ops/sec ±10.07% (69 runs sampled)
MongoDB x 252 ops/sec ±9.27% (47 runs sampled)
Mongoose x 126 ops/sec ±9.93% (64 runs sampled)
MongoDB x 279 ops/sec ±8.67% (47 runs sampled)

--

--

I have a very keen interest in Computers. I practice few programming languages on a regular routine

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
bugwheels94

bugwheels94

I have a very keen interest in Computers. I practice few programming languages on a regular routine