question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Only _id column is returned on v5.x.x

See original GitHub issue

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.

// 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:open
  • Created 6 years ago
  • Reactions:1
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
JoelParkecommented, Sep 14, 2017

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 https://github.com/umaxfun: it’s because you have an empty string as the second argument so it’s not fetching any fields.

@JoelParke https://github.com/joelparke: I haven’t been able to reproduce, I have some test cases for streaming (https://github.com/ Automattic/monk/blob/2f3dd7f171bc7cb6dc201fda5534a4 ffa964a89a/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

β€” You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Automattic/monk/issues/208#issuecomment-328493521, or mute the thread https://github.com/notifications/unsubscribe-auth/ALta4gb6EW3ZeqDhNryjUXQlEUrY4V7uks5shRAzgaJpZM4N4pMh .

1reaction
mathieudutourcommented, Sep 11, 2017

@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

Read more comments on GitHub >

github_iconTop Results From Across the Web

An explicit value for the identity column in table can only be ...
SQL Server won't let you insert an explicit value in an identity column unless you use a column list. Thus, you have the...
Read more >
Foreign Key Constraint | CockroachDB Docs
The `FOREIGN KEY` constraint specifies a column can contain only values exactly matching existing values from the column it references.
Read more >
Legacy SQL Functions and Operators | BigQuery - Google Cloud
Returns the exact number of non-NULL, distinct values for the specified field. FIRST(), Returns the first sequential value in the scope of the...
Read more >
INSERT (Transact-SQL) - SQL Server - Microsoft Learn
For example, an INSERT into a multi-table view must use a column_list that references only columns from one base table.
Read more >
Database: Migrations - The PHP Framework For Web Artisans
The up method is used to add new tables, columns, or indexes to your database, while the down method should reverse the operations...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found