I have a large nested object defined as a single document from a mobile app that I want to backup to MongoDB via an Express-powered REST API. This is not something that will be done often or in real time, so I don't need to build a full transactional API, I'd rather just backup and restore as a single action if possible.
Doing this on the command line is simple, but I'd like to build a REST API to do this programmatically. Example command line:
mongoimport --db workouttest --collection workouts --file workouts.json --jsonArray
Sample JSON used in the mongoimport example above, defined by the following schema:
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var workoutSchema = new Schema({
name: String,
startDate: Date,
userProfile: {
age: Number,
name: String,
bodyWeight: Number
},
program: [{
name: String,
goal: Number,
notes: String,
workoutDiary: [{
date: Date,
sets: [{
repCount: Number,
weight: Number
}]
}]
}]
});
module.exports = mongoose.model('Workout', workoutSchema);