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?
48 Replies
a guid doesn't auto generate itself
show the code where you're creating this object
where in this code do you assign a value to
Id
im not assigning I thought guid generating a unique id everytime after i create model
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)
this is default for my program i guess
there is no default for your program, it's coming from somewhere
probably your frontend
i didn't want to use objectId. I was trying make the program minimum dependent to mongodb
Jimmacle
REPL Result: Success
Console Output
Compile: 408.483ms | Execution: 20.837ms | React with ❌ to remove this embed.
I don't have frontend its just auto swagger injected
is a guid being sent in your http request?
I guess so
this is default
everytime same id
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
good idea but the problem with id? how should i solve it
just want auto generated id without using objectId
by using !e Guid.NewGuid()
Jimmacle
REPL Result: Success
Result: Guid
Compile: 226.023ms | Execution: 17.181ms | React with ❌ to remove this embed.
Have the database generate them ¯\_(ツ)_/¯
I better not but if there's no option i have to ¯\_(ツ)_/¯
Why not?
because I'm trying to minimize the program's dependency on MongoDB by using as little MongoDB library as possible
if your program uses a a database it uses a database
trying to abstract that away will only cause pain and suffering
Other databases can generate uuids as well
yh but I want to make it generic so if I change the db someday. i'll modify only repos
that rarely happens
Besides, you're not gonna switch from Mongo to a proper relational database easily anyway lol
why mongo anyway
It's web-scale :KEKW:
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
yh I know im just trying to impress my senior
or causing performance issues due to not having fine control over queries
who knows it's just basic task has given to me
so don't overcomplicate it
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
maybe, we don't know what your requirements are
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
if there is no reason to abstract mongo then i wouldn't, it's spending extra time on something that's not needed
If the task was to do it in as generic of a way as possible, then sure
Do worry about it
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
💀
agreed
with json support in all the major relational databases who even needs a document database anymore
¯\_(ツ)_/¯
so you say this will work
if you want to create a unique GUID in C#, that's what you want
where do I implement it after create operation?
that method gives you a GUID, use it to set the Id of your post