Monday, 3 April 2017

Error in mongodb export in node,js

I was trying to connect mongodb using node.js. I stumbled on a problem. I am getting require(...).pure is not a function error . I tried to use the exact code from this site "https://mongodb.github.io/node-mongodb-native/api-generated/collection.html" My code is given below.

var Db = require('mongodb').Db,
MongoClient = require('mongodb').MongoClient,
Server = require('mongodb').Server,
ReplSetServers = require('mongodb').ReplSetServers,
ObjectID = require('mongodb').ObjectID,
Binary = require('mongodb').Binary,
GridStore = require('mongodb').GridStore,
Grid = require('mongodb').Grid,
Code = require('mongodb').Code,
BSON = require('mongodb').pure().BSON,
assert = require('assert');

var uri = "mongodb://sa:psvitagamer5@cluster0-shard-00-00-
 tpfog.mongodb.net:27017,cluster0-shard-00-01-
  tpfog.mongodb.net:27017,cluster0-shard-00-02-
  tpfog.mongodb.net:27017/myNodeDb?ssl=true&replicaSet=Cluster0-shard-
  0&authSource=admin";


 MongoClient.connect(uri, function(err, db) {

   var collection = db.collection("userCollection");

    collection.insert({hello:'world_no_safe'});

   // Wait for a second before finishing up, to ensure we have written 
     the item to disk
   setTimeout(function() {

  // Fetch the document
   collection.findOne({hello:'world_no_safe'}, function(err, item) {
      assert.equal(null, err);
      assert.equal('world_no_safe', item.hello);
      db.close();
   })
   }, 100);
  //db.close();
});

Please let me know your suggestions.



via Manij Rai

No comments:

Post a Comment