Create and update subscribers in c#
Hi Team I'm following below steps to create/update subscribers in Novu
Creating subscribers is working fine. I can see subscribers in novu dashboard but update is not working am i missing somethig ?
private async Task UpdateStudentData(StudentAggregatedDetails updatedStudent)
{
var filter = Builders<subscribers>.Filter.Eq("subscriberId", updatedStudent.UserReferenceId);
if (filter != null)
{
var update = Builders<subscribers>.Update
.Set(s => s.firstName, updatedStudent.FirstName)
.Set(s => s.lastName, updatedStudent.LastName)
.Set(s => s.email, updatedStudent.Email)
.Set(s => s._organizationId, organizationId)
.Set(s => s._environmentId, environmentId)
.Set(s => s.data.NextEncounterDateInStudentTimeZone, updatedStudent.NextEncounterDateInStudentTimeZone)
.Set(s => s.data.StartLevel, updatedStudent.StartLevel);
await _mongoCollection.UpdateOneAsync(filter, update);
}
}
public subscribers MapToSubscribers(StudentAggregatedDetails studentDetails)
{
var NewUser = new subscribers
{
// Map properties from StudentAggregatedDetails to subscribers
subscriberId = studentDetails.UserReferenceId,
firstName = studentDetails.FirstName,
lastName = studentDetails.LastName,
email = studentDetails.Email,
createdAt = DateTime.Now.ToUniversalTime(),
updatedAt = DateTime.Now.ToUniversalTime(),
_environmentId = environmentId,
_organizationId = organizationId,
deleted = false,
data = new Data
{
StartLevel = studentDetails.StartLevel,
EndLevel = studentDetails.EndLevel,
}
};
7 Replies
@Pawan Jain any help on this please ?
@Puvi Thanks for tagging.
Unfortunately, I don't have experience with C# or .Net.
What is the exact issue you are facing in update subscriber method?
While updating
I can see changes in novu db.but in ui its still the old data and when I try to get data from post man at that time also its still old data
@Pawan Jain
That should not happen
if data is changed in DB then it should be updated on web and api response
Yes 🥲
@Pawan Jain I have one doubt. In get call, data will be retrieved from data base or it will be from any session ?
it will be retrieved from DB
Thanks for the confirmation @Pawan Jain, Do I Missing any important data while updating ? due to that my recoed missing in get call ?
Found solution
we need to clear redis cache for that particular user using key genrated by buildSubscriberKey Method