Only _id column is returned on v5.x.x
See original GitHub issueI 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.
// 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?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:7 (2 by maintainers)
Top GitHub Comments
I will try and put something together in a few daysβ¦
On Mon, Sep 11, 2017 at 4:49 AM, Mathieu Dutour notifications@github.com wrote:
@umaxfun: itβs because you have an empty string as the second argument so itβs not fetching any fields.
@JoelParke: I havenβt been able to reproduce, I have some test cases for streaming (https://github.com/Automattic/monk/blob/2f3dd7f171bc7cb6dc201fda5534a4ffa964a89a/test/collection.js#L222-L266) and they work as expected. It would be super useful if you manage to create a test case that fails