feat: Split v1 and v2 apis
This commit is contained in:
41
scripts/migrate.js
Normal file
41
scripts/migrate.js
Normal file
@@ -0,0 +1,41 @@
|
||||
'use strict';
|
||||
require('dotenv').config();
|
||||
const { ROOT_PATH, LIB_PATH, API_CONFIG } = process.env;
|
||||
const apiConfig = require( `${ROOT_PATH}/${API_CONFIG}` );
|
||||
const { getModel } = require( './src/lib/Models' );
|
||||
const mongoose = require('mongoose');
|
||||
const Model = getModel('loads');
|
||||
|
||||
mongoose.connect(
|
||||
apiConfig.mongodb,
|
||||
{ useNewUrlParser: true }
|
||||
).then( ( val ) => {
|
||||
console.log( `MongoDB Connected : ${ apiConfig.mongodb }` );
|
||||
});//catch throw error so service stops!
|
||||
|
||||
async function migrate(){
|
||||
const list = await Model.find({
|
||||
"postedBy":"65f11b7c02030a15ebd59a8f"
|
||||
},"createdAt").sort("-createdAt").exec();
|
||||
// let list = await Model.find({ _id : [ "64fce4083f60cc00182470e0", "65efaffaa2029862cd6d90ef",
|
||||
// "65f2679402030a15ebd59d63",
|
||||
// "65f3a64902030a15ebd5a4f6",
|
||||
// "6610bbc756c2a72c91085d5c"]
|
||||
// }, "createdAt" );
|
||||
|
||||
for (const element of list ){
|
||||
console.log( element );
|
||||
console.log( new Date(element.createdAt) );
|
||||
}
|
||||
|
||||
const date = Date.now();
|
||||
// console.log( list.length , affected );
|
||||
await mongoose.disconnect();
|
||||
return "Done";
|
||||
}
|
||||
|
||||
migrate().then( (out)=>{
|
||||
console.log( out );
|
||||
} ).catch( (error) => {
|
||||
console.error( error );
|
||||
});
|
||||
Reference in New Issue
Block a user