Automattic / Automattic/monk

Only _id column is returned on v5.x.x

Open
#208 7 comments 1 reaction 0 assignees View on GitHub
bug need repro
Dominant language
JavaScript
Stars
1.8k
Forks
180
PR merge metrics
No merged PRs in 30d

Description

I know v6 has been released, but since it is a semver-major release, I'd like to share this weird situation.

This situation is resolved by updating monk to v6.

---

First, I'm running MongoDB 3.4.14. I haven't tested this with other versions of MongoDB.

```
$ cat version.js
var MongoClient = require("mongodb").MongoClient;

MongoClient.connect("mongodb://some-server", function(err, db) {
db.admin().serverStatus(function(err, info) {
console.log(info.version);
});
});

$ node version.js
3.4.4
```

`monk` has dependency of `mongodb ^5.1.18`, so I started with two minimal dependencies.

```
$ cat package.json
{
"dependencies": {
"mongodb": "2.1.18",
"monk": "5.0.2"
}
}

$ rm -rf node_modules

$ npm install
npm WARN deprecated mongodb@2.1.18: Please upgrade to 2.2.19 or higher
/source/code
├─┬ mongodb@2.1.18
│ ├── es6-promise@3.0.2
│ ├─┬ mongodb-core@1.3.18
│ │ ├── bson@0.4.23
│ │ └─┬ require_optional@1.0.0
│ │ ├── resolve-from@2.0.0
│ │ └── semver@5.3.0
│ └─┬ readable-stream@1.0.31
│ ├── core-util-is@1.0.2
│ ├── inherits@2.0.3
│ ├── isarray@0.0.1
│ └── string_decoder@0.10.31
└─┬ monk@5.0.2
├─┬ debug@2.6.8
│ └── ms@2.0.0
├── monk-middleware-cast-ids@0.2.1
├── monk-middleware-fields@0.2.0
├── monk-middleware-handle-callback@0.2.0
├── monk-middleware-options@0.2.1
├── monk-middleware-query@0.2.0
├── monk-middleware-wait-for-connection@0.2.0
└── object-assign@4.1.1
```

And I made two small test scripts.

```js
// test.js
var MongoClient = require("mongodb").MongoClient;

MongoClient.connect("mongodb://some-server", function(err, db) {
var collection = db.collection("games");
collection.find({}).toArray(function(err, docs) {
console.log(docs);
});
});

// test2.js
var monk = require("monk");
var db = monk("some-server");
var games = db.get("games");
games.find({}).then(function(docs) {
console.log(docs);
});
```

With `monk v5.0.2` and `mongodb v2.1.18`, native mongo driver works fine, but monk is breaking.

```
$ node test.js
[ { _id: 592295d911ef78ca7d8b88e9,
(...) },
{ _id: 5937dff35a060d5563160b12,
(...) },
{ _id: 593826b85a060d5563163fa8,
(...) } ]

$ node test2.js
[ { _id: 592295d911ef78ca7d8b88e9 },
{ _id: 5937dff35a060d5563160b12 },
{ _id: 593826b85a060d5563163fa8 } ]
```

Updating mongo driver to the latest version(`2.2.28` for now) doesn't help.

```
$ cat package.json
{
"dependencies": {
"mongodb": "2.2.28",
"monk": "5.0.2"
}
}

$ rm -rf node_modules

$ npm install
/source/code
├─┬ mongodb@2.2.28
│ ├── es6-promise@3.2.1
│ ├─┬ mongodb-core@2.1.12
│ │ ├── bson@1.0.4
│ │ └─┬ require_optional@1.0.0
│ │ ├── resolve-from@2.0.0
│ │ └── semver@5.3.0
│ └─┬ readable-stream@2.2.7
│ ├── buffer-shims@1.0.0
│ ├── core-util-is@1.0.2
│ ├── inherits@2.0.3
│ ├── isarray@1.0.0
│ ├── process-nextick-args@1.0.7
│ ├─┬ string_decoder@1.0.2
│ │ └── safe-buffer@5.0.1
│ └── util-deprecate@1.0.2
└─┬ monk@5.0.2
├─┬ debug@2.6.8
│ └── ms@2.0.0
├── monk-middleware-cast-ids@0.2.1
├── monk-middleware-fields@0.2.0
├── monk-middleware-handle-callback@0.2.0
├── monk-middleware-options@0.2.1
├── monk-middleware-query@0.2.0
├── monk-middleware-wait-for-connection@0.2.0
└── object-assign@4.1.1

$ node test.js
[ { _id: 592295d911ef78ca7d8b88e9,
(...) },
{ _id: 5937dff35a060d5563160b12,
(...) },
{ _id: 593826b85a060d5563163fa8,
(...) } ]

$ node test2.js
[ { _id: 592295d911ef78ca7d8b88e9 },
{ _id: 5937dff35a060d5563160b12 },
{ _id: 593826b85a060d5563163fa8 } ]
```

And updating monk to the latest version finally resolves this problem.

```
$ cat package.json
{
"dependencies": {
"mongodb": "2.2.28",
"monk": "6.0.0"
}
}

$ rm -rf node_modules

$ npm install
/source/code
├─┬ mongodb@2.2.28
│ ├── es6-promise@3.2.1
│ ├─┬ mongodb-core@2.1.12
│ │ ├── bson@1.0.4
│ │ └─┬ require_optional@1.0.0
│ │ ├── resolve-from@2.0.0
│ │ └── semver@5.3.0
│ └─┬ readable-stream@2.2.7
│ ├── buffer-shims@1.0.0
│ ├── core-util-is@1.0.2
│ ├── inherits@2.0.3
│ ├── isarray@1.0.0
│ ├── process-nextick-args@1.0.7
│ ├─┬ string_decoder@1.0.2
│ │ └── safe-buffer@5.0.1
│ └── util-deprecate@1.0.2
└─┬ monk@6.0.0
├─┬ debug@2.6.8
│ └── ms@2.0.0
├── monk-middleware-cast-ids@0.2.1
├── monk-middleware-fields@0.2.0
├── monk-middleware-handle-callback@0.2.0
├── monk-middleware-options@0.2.1
├── monk-middleware-query@0.2.0
├── monk-middleware-wait-for-connection@0.2.0
└── object-assign@4.1.1

$ node test.js
[ { _id: 592295d911ef78ca7d8b88e9,
(...) },
{ _id: 5937dff35a060d5563160b12,
(...) },
{ _id: 593826b85a060d5563163fa8,
(...) } ]

$ node test2.js
[ { _id: 592295d911ef78ca7d8b88e9,
(...) },
{ _id: 5937dff35a060d5563160b12,
(...) },
{ _id: 593826b85a060d5563163fa8,
(...) } ]
```

---

But weirdly, it was working fine with `monk v5.0.1` and `mongodb v2.2.27`. So I tried to find the exact version of the breaking point, but failed to reproduce this situation again.

Won't fix, maybe?

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the reported test.js and test2.js scripts and compare their results under monk v5.0.2, mongodb 2.2.28, and monk v6.0.0. Check the monk find path and its middleware dependencies to identify the version-related behavior; done would mean explaining or correcting why Monk v5 returns only _id, noting that v6 reportedly resolves it.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, mongodb
Domain
database
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.