How to initialize mongodb in node?

I used the apigee management api to install mongodb in my node_modules. But when I try to initialize it I always get SyntaxError: invalid object initializer.

var MongoClient = require('mongodb').MongoClient;
Solved Solved
0 1 272
1 ACCEPTED SOLUTION

Alright, I figured it out cos aint no one looking out for me.

There were several things I did for this to work:

  1. In package.json withing the resources/node in ur api proxy I specified which version of mongodb to use. I used version 2.2.12 because I suspect the new version is not supported by apigee.
  2. In Apigee management api in the manage node packaged modules used the "command=install&production=false" for installation of dependencies from pacage.json file.

After thew two steps node.js recognised MongoClient. Furthermore to connect to mlabs make sure you specify the version you are using in apigee when copying the uri. Also if you have special characters in your password for ur database user you need to ASCII encode it in your uri. link here https://ascii.cl/

e.g. password! => password%21

View solution in original post

1 REPLY 1

Alright, I figured it out cos aint no one looking out for me.

There were several things I did for this to work:

  1. In package.json withing the resources/node in ur api proxy I specified which version of mongodb to use. I used version 2.2.12 because I suspect the new version is not supported by apigee.
  2. In Apigee management api in the manage node packaged modules used the "command=install&production=false" for installation of dependencies from pacage.json file.

After thew two steps node.js recognised MongoClient. Furthermore to connect to mlabs make sure you specify the version you are using in apigee when copying the uri. Also if you have special characters in your password for ur database user you need to ASCII encode it in your uri. link here https://ascii.cl/

e.g. password! => password%21