You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, ts-mongoose contributors, this is a great library.
My question is: is there an example of how to push new subdocument instance into existing Document array?
Thank you!
Here is our use case.
Here is what we try to setup
import{createSchema,ExtractDoc,ExtractProps,Type,typedModel}from'ts-mongoose';constNoticeAckSchema=createSchema({wikiUserName: Type.string(),userGaId: Type.string(),ackedAt: Type.date(),},);/** * Schema for a NoticeMessage * * Example { messageId: "NoticeUSerLevelsRfC", defaultMessage: "Hi editors, we have a Request For Comments we like your feedback.", url: 'https://meta.wikimedia.org/wiki/WikiLoop/DoubleCheck/something', createdAt: "2020-08-20 01:01 UTC", asks: [ { wikiUserName: "JohnSmith", userGaId: "...", ackedAt: "2020-08-20 02:02 UTC", } ], beginAt: "2020-08-20 00:00 UTC", endAt: "2020-09-14 00:00 UTC", } */constNoticeMessageSchema=createSchema({messageId: Type.string({required: true,index: true,unique: true}),// e.g.defaultMessage: Type.string({required: true}),// The default message content, in case translations are not currently available yet.url: Type.string({required: false}),createdAt: Type.date({required: true,index:true}),acks: Type.array().of(Type.schema({required:false}).of(NoticeAckSchema)),beginAt: Type.date({required: true,index:true}),endAt: Type.date({required: true,index:true}),},);exportconstNoticeMessage=typedModel('NoticeMessage',NoticeMessageSchema,'NoticeMessage');exporttypeNoticeMessageDoc=ExtractDoc<typeofNoticeMessageSchema>;exporttypeNoticeMessageProps=ExtractProps<typeofNoticeMessageSchema>;exporttypeNoticeAckProps=ExtractProps<typeofNoticeAckSchema>;exporttypeNoticeAckDoc=ExtractDoc<typeofNoticeAckSchema>;
And here is an example code what we run
import{initDotEnv,initMongoDb}from'~/server/init-util';import{NoticeMessage}from'~/shared/models/notice-message-model';constcreateNoticeMain=asyncfunction(){awaitinitDotEnv();awaitinitMongoDb();letnoticeMessage=awaitNoticeMessage.create({messageId: "Notice-UserLevelsRfC1",defaultMessage: "Hi editors, we have a Request For Comments we like your feedback.",url: 'https://meta.wikimedia.org/wiki/WikiLoop/DoubleCheck/RfC:Levels_for_WikiLoop_DoubleCheck_Reviewers',createdAt: newDate("2020-08-20 01:01 UTC"),acks: [{wikiUserName: "RandomUser",userGaId: "GA1.2.1390141177.1578026694",// random GA ID,ackedAt: newDate(),}],beginAt: newDate("2020-08-20 00:00:00 UTC"),endAt: newDate("2020-09-14 00:00:00 UTC"),});noticeMessage.acks.push({wikiUserName: "RandomUser",userGaId: "GA1.2.1395341177.1578021394",// random GA ID,ackedAt: newDate(),});console.log(`done`);}createNoticeMain().then(()=>{console.log(`CMD Done!`);process.exit(0);});
And it seems failing at
noticeMessage.acks.push({
wikiUserName: "RandomUser",
userGaId: "GA1.2.1395341177.1578021394", // random GA ID,
ackedAt: new Date(),
});
Hi, ts-mongoose contributors, this is a great library.
My question is: is there an example of how to push new subdocument instance into existing Document array?
Thank you!
Here is our use case.
Here is what we try to setup
And here is an example code what we run
And it seems failing at
with error
The text was updated successfully, but these errors were encountered: