Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
272 views
in Technique[技术] by (71.8m points)

mongodb - Why _id being an obstacle to find unique

I was trying to answer this SO post

I am seeing an insane behaviour where _id is stopping setUnion/addToSet find unique object.

playground

playground without _id

Sample element in one doc:

"newPMList": [
  {
    /**"_id": "5feb10c4906c880076ce5fa6",
    */"project": "5feb10b6906c880076ce5fa5",
    "market": "5feb0f44906c880076ce5f9d",
    "url": "https://www.example.com/place",
    "createdAt": "2020-12-29T11:19:32.945Z",
    "updatedAt": "2020-12-29T11:19:32.945Z",
    "__v": 0
  }
]

It will be present as it is in another document.

Any suggestions please?


EDIT:

Out of curiosity, I tried the same in my local server.

My bad, When I try the same in my local mongo server, it works.

Playground is an obstacle in this case. I think it reprocesses the data before submitting to the mongo server by removing _id fields and generating new one.

But couldn't justify the same. I am happy to delete the question also if it doesn't make sense. please advise.

question from:https://stackoverflow.com/questions/65830148/why-id-being-an-obstacle-to-find-unique

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...