javascript - How to Insert records into mongo with Node where records have an $oid -


I'm new to Mongo and node and I'm trying to create a script which essentially works like a rail Does rake db: seed work where I have a set of .json files in a specific folder, and when I run the $ node seed then this is my seed.js file Which will take them all .json files and files based on the filename of the .json file Mixes

Basically I run the $ node seed and it executes the / seed .js which is /seeds/account.json , / Seed / Customer. Jason , etc.

In this way, I can limit this code and then the next developer can run just $ node beed and its Mongo instance can work with some data Will come for you.

The problem I have is that I have data from my collection dump, so some sample data from the account looks like this:

  {_id : {'$ Oid': '534d832177da4e0d380 00001'}, id: 1, name: some, datetime: '2014-04-15T14: 06: 09-05: 00'}   

Now when I run the $ node , I get this error:

  [error: key $ OID should not start with '$']   

Is there any way to complete this error or do I have all my .jso Remove all $ oid from n files?

seed.js:

  var requires mongoose = 'magos'); mongoose.connect ('MongoDB: // local host / testdb'); Var dir = './seeds'; Var DB = Mongoose Connection; // If any one is db.on ('error', console.error.bind (console, 'database connection error:'), then show connection error; // If we successfully set Mongo DB.ones ('Open', function Callback) {var fs = need ('fs'); // is used to get all the files in a directory // Read all the files folder fs.readdir (dir, function (err, list ) {// If the error is interrupted, then enter the error (error) {console.log ('error:' + err);} // Each file in the list list For .for Ikea (file) Set file name without collection of {// archive archive _name = file.split (".") [0]; var requires parsedJSON = (DIR + '/' + File); (Var i = 0; i & lt; parsedJSON.length; i ++) {// Calculates the number of records in the collection db.collection ('cohort'). Calculation (function (error, calculation) ) {If (err) {console (mistake) {if (err) {console.log (err)}} console.log (record [0]); console.log ("record" + record [0]) Added to the form;}}}}}}}}}}};   

Or is there a library which is already such a Is present for work?

field names do not begin with a dollar sign ($) character Can.

Part of mongodb spec because it is $ $ or $$ like unset

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -