guid doesn't change after post

I defined my model ID's as guid to make it auto generated but after creating model. Is it about scope?
No description
No description
48 Replies
Jimmacle
Jimmacle9mo ago
a guid doesn't auto generate itself show the code where you're creating this object
only you know
only you knowOP9mo ago
No description
No description
only you know
only you knowOP9mo ago
No description
Jimmacle
Jimmacle9mo ago
where in this code do you assign a value to Id
only you know
only you knowOP9mo ago
im not assigning I thought guid generating a unique id everytime after i create model
Jimmacle
Jimmacle9mo ago
no, a default guid is just 0 if you want mongodb to generate one i don't know how to do that because i don't use mongodb (and most people shouldn't)
only you know
only you knowOP9mo ago
this is default for my program i guess
No description
Jimmacle
Jimmacle9mo ago
there is no default for your program, it's coming from somewhere probably your frontend
only you know
only you knowOP9mo ago
i didn't want to use objectId. I was trying make the program minimum dependent to mongodb
MODiX
MODiX9mo ago
Jimmacle
REPL Result: Success
Guid guid = default;
Console.WriteLine(guid);
Guid guid = default;
Console.WriteLine(guid);
Console Output
00000000-0000-0000-0000-000000000000
00000000-0000-0000-0000-000000000000
Compile: 408.483ms | Execution: 20.837ms | React with ❌ to remove this embed.
only you know
only you knowOP9mo ago
I don't have frontend its just auto swagger injected
Jimmacle
Jimmacle9mo ago
is a guid being sent in your http request?
only you know
only you knowOP9mo ago
I guess so
only you know
only you knowOP9mo ago
this is default
No description
only you know
only you knowOP9mo ago
everytime same id
Jimmacle
Jimmacle9mo ago
that's most likely an example value generated by swagger you definitely don't want the end user to be providing IDs for your database which means you need to not use your DB model as a DTO, create separate classes to hold the data you actually want in your requests and responses
only you know
only you knowOP9mo ago
good idea but the problem with id? how should i solve it just want auto generated id without using objectId
Jimmacle
Jimmacle9mo ago
by using !e Guid.NewGuid()
MODiX
MODiX9mo ago
Jimmacle
REPL Result: Success
Guid.NewGuid()
Guid.NewGuid()
Result: Guid
99b3e8e2-a376-4d92-acd0-13a75fa21e77
99b3e8e2-a376-4d92-acd0-13a75fa21e77
Compile: 226.023ms | Execution: 17.181ms | React with ❌ to remove this embed.
Angius
Angius9mo ago
Have the database generate them ¯\_(ツ)_/¯
only you know
only you knowOP9mo ago
I better not but if there's no option i have to ¯\_(ツ)_/¯
Angius
Angius9mo ago
Why not?
only you know
only you knowOP9mo ago
because I'm trying to minimize the program's dependency on MongoDB by using as little MongoDB library as possible
Jimmacle
Jimmacle9mo ago
if your program uses a a database it uses a database trying to abstract that away will only cause pain and suffering
Angius
Angius9mo ago
Other databases can generate uuids as well
only you know
only you knowOP9mo ago
yh but I want to make it generic so if I change the db someday. i'll modify only repos
Jimmacle
Jimmacle9mo ago
that rarely happens
Angius
Angius9mo ago
Besides, you're not gonna switch from Mongo to a proper relational database easily anyway lol
Jimmacle
Jimmacle9mo ago
why mongo anyway
Angius
Angius9mo ago
It's web-scale :KEKW:
Jimmacle
Jimmacle9mo ago
the real problem is by making your data access that generic you prevent yourself from using any real features of whatever db engine you're using
only you know
only you knowOP9mo ago
yh I know im just trying to impress my senior
Jimmacle
Jimmacle9mo ago
or causing performance issues due to not having fine control over queries
only you know
only you knowOP9mo ago
who knows it's just basic task has given to me
Jimmacle
Jimmacle9mo ago
so don't overcomplicate it
only you know
only you knowOP9mo ago
it makes sense I just wanted to do the task as I understand him. maybe I'm wrong I should ask him to make it clear
Jimmacle
Jimmacle9mo ago
maybe, we don't know what your requirements are
Angius
Angius9mo ago
If the task is to make it work with Mongo, make it work with Mongo and don't worry about the inevitable future migration to Postgres
Jimmacle
Jimmacle9mo ago
if there is no reason to abstract mongo then i wouldn't, it's spending extra time on something that's not needed
Angius
Angius9mo ago
If the task was to do it in as generic of a way as possible, then sure Do worry about it
only you know
only you knowOP9mo ago
I think the company considering to move to mongo that's why they want me to do some things about it it's my first time with mongo also
Angius
Angius9mo ago
💀
only you know
only you knowOP9mo ago
agreed
Jimmacle
Jimmacle9mo ago
with json support in all the major relational databases who even needs a document database anymore
only you know
only you knowOP9mo ago
¯\_(ツ)_/¯ so you say this will work
Jimmacle
Jimmacle9mo ago
if you want to create a unique GUID in C#, that's what you want
only you know
only you knowOP9mo ago
where do I implement it after create operation?
Jimmacle
Jimmacle9mo ago
that method gives you a GUID, use it to set the Id of your post
Want results from more Discord servers?
Add your server