Unable to read property "ObjectID" from undefined

I am deploying / trying to understand a mongodb-rest project. When I run only the rest.jsscript, I get this error:

TypeError: Cannot read property 'ObjectID' of undefined
    at app.post.connection.connect.res.status.json.message (/var/lib/openshift/5556b4c4fcf9336abf0000de/app-root/runtime/repo/server.js:99:32)

on this line when I try to process the message PUT:

var spec = {'_id': new BSON.ObjectID(req.params.id)};

I have the same include lines as rest.js

  var mongodb = require("mongodb");
  var BSON = mongodb.BSONPure;

but works on servers OpenShift.

Any idea what's wrong?

UPDATE

I tried using the same package:

  var bson = require("bson");
  var BSON = bson.BSONPure.BSON;
  //var BSON = mongodb.BSONPure;

got the same error

+4
source share
1 answer

Try using bson package instead of mongodb:

var BSON = require('bson').BSONPure
+7
source

Source: https://habr.com/ru/post/1589181/


All Articles