I have an existing schema like
exports.OldCollectionSchema= new Schema({
Id: { type: Schema.ObjectId },
parentId: { type: Schema.ObjectId },
userId: { type : String },
userName: { type : String })
Now, I waned to use the above collection in two scenarios by adding a new field type
type would be scenario a or scenario b
so I wanted to fetch the old records + type = "scenario a" and to show that in a page
How is it possible ?
I do believe Mongoose has a __v field denoting version however I am no Mongoose expert so I will just paste the easy hacky query that you can do:
db.col.find({type: {$exists: false, $in: ['a']}});
That will basically say: "Get all the records where they don't yet have a scenario (basically the ones before this schema) and combine them with the ones that have a type of 'a'"
Actually a better way is just to use null here:
db.col.find({type: {$in: ['a', null]}});