I am currently working on a mongo script to efficiently import a jsonArray
from a JSON
file. The script I am developing is in .js
format and I plan to run it using the load()
command within the mongo shell. Is there a feasible method for accomplishing this task with a mongo script
?
While I am aware that I could use mongoimport
as an alternative solution, my preference lies in finding a way to achieve this through a scripting approach.
Below are the contents of my current script, where the import section is yet to be implemented:
var db = connect("localhost:27017/fypgui");
//Import json data into "crimes" collection goes here
var crimes = db.crimes.find();
while (crimes.hasNext()){
var item = crimes.next();
var year =(item.crime_date != null)?(new Date(item.crime_date)).getFullYear():null;
db.crimes.update( {_id: item._id}, {$set: {crime_year: year}});
}