// tslint:disable:no-console // import * as moment from 'moment'; import * as mongoose from 'mongoose'; import { chevre } from '../../../lib/index'; // const project = { id: String(process.env.PROJECT_ID) }; async function main() { await mongoose.connect(process.env.MONGOLAB_URI); const offerRepo = new chevre.repository.Offer(mongoose.connection); const cursor = offerRepo.getCursor( { // 'project.id': { $eq: project.id } 'priceSpecification.appliesToMovieTicket': { $exists: true, $type: 'array' // $not: { $type: 'array' } } }, { // _id: 1, // ownedFrom: 1, // typeOfGood: 1 } ); console.log('offers found'); let i = 0; let isArrayCount = 0; let updateCount = 0; await cursor.eachAsync(async (doc) => { i += 1; const offer = doc.toObject(); const applieToMovieTicket = offer.priceSpecification?.appliesToMovieTicket; if (Array.isArray(applieToMovieTicket)) { console.log('is Array', offer.project.id, offer.id, i); isArrayCount += 1; } else if (typeof (applieToMovieTicket)?.typeOf === 'string') { console.log('is not array', offer.project.id, offer.id, i); updateCount += 1; } else { console.log('no applieToMovieTicket', offer.project.id, offer.id, i); } }); console.log(i, 'offers checked'); console.log(isArrayCount, 'isArrayCount'); console.log(updateCount, 'offers updated'); } main() .then() .catch(console.error);