Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

db.attendance.

insert({
subject: 'Mathematics'//changes to a variable
date:'2/3/2020'// selected date variable
class: 'JSS1A' // class variable
term: ''
session: ''
Present: [id]// array of ids
absent: [id]
-----------------
attend:[
{//embedded objects having arrays as embedded
class: 1,
date: '',
Present: '',
Absent:''
},
{
class :2, //increment class 1
date: '',
Present: '',
Absent:''
},
{
class: 3,// increment class 2
date: '',
Present: '',
Absent:'',
}
]
});
// can i do in a way it updatesthisparticular subject instead of always creating
new one

db.records.insert({ Insert command.


subject: 'Mathematics',
class: 'JSS1A',
term: '1st',
session: '2019/2020',
attend:[
{
class: 1,
date: '21/May/2020',
Present: ['06','17','24','32'],
Absent:['12','24','15']
},
{
class :2,
date: '22/May/2020',
Present: ['06','17','24','32','12','24','15'],
Absent:[]
},
{
class: 3,
date: Date(),
Present: ['06','17','12','24','15'],
Absent:['32']
}
]
});
db.records.update({ _id: ObjectId("5ec9a52e3099d561650c7b41")},// update command
using _id
{
$push:{
attend:{
class: 4,
date: Date(),
Present: [],
Absent: ['06','17','12','24','15']

}
}
})

Use upsert to merge update and insert command where subject=, class=, term=,
session=.so it will insert if not found butupdate if it is found

db.records.update({subject: 'English' ,class: 'JSS1A', term: '1st', session:


'2019/2020'},
{
$push: {
attend:
{
class: 1,
date: Date(),
Present: ['06','17','12','24','15'],
Absent: []
}
}
},
{
upsert:true
})

You might also like