InvalidKey in MongoDB and Node.js -


i have file has key ip "10.11.190.14:cgi6web-1": . when try insert file in mongodb, following error:

error: key 10.11.190.14:cgi6-web-1 must not contain '.' @ error (unknown source).

i dont have permissions change file , there work around write file mongodb ip key.

my code follows:

var mongoclient = require('./lib/mongodb').mongoclient; var file = require (__dirname + '/functions.json');  mongoclient.connect('mongodb://phx8b03c-fb1d',     function (err, client) {         if (err) throw err;          client.createcollection('lbtopology' , function (err, collection) {             if (err) throw err;              collection.insert(file, 'lbtopology' , function (err) {                 if (err) throw err;                  client.close(function (err) {                     if (err) throw err;                      console.log('done');                 });             });         });     }) 

can please me this?

you possibly change "pools" as in file array, moving key it's property of each inner object:

{     "pools": [         {             "_key": "10.2.90.83: cgi5-web-1-80",             "tags": "dc=phxodbpool=cgi5-web-1-80",             "oname": "10.2.90.83: cgi5-web-1-80",             "pname": "syi-web",             "oid_suffix": [                 19             ]         },         // ...     ] } 

you can use object.keys() , .map() accomplish this:

var file = require (__dirname + '/functions.json');  file.pools = object.keys(file.pools).map(function (key) {     var pool = file.pools[key];     pool._key = key;     return pool; }); 

[edit] lbs bit more interesting each object has pnames needs same treatment. also, since each item under pnames number, you'll have create object hold key.

file.lbs = object.keys(file.lbs).map(function (key) {     var lb = file.lbs[key];     lb._key = key;      lb.pnames = object.keys(lb.pnames).map(function (pkey) {         return { key: pkey, value: lb.pnames[pkey] };     });      return lb; }); 

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -