skip to Main Content

Mongodb – Upsert many documents based on _id

I need to upsert many documents based on _id. E.g. document_1 = {_id:"1", "age":11, "name":"name1"} document_2 = {_id:"2", "age":22, "name":"name2"} I wrote the below db.my_collection.updateMany( { _id: {"$in":["1","2"] } }, [ {$set: {_id:"1", "age":11, "name":"name1"}}, {$set: {_id:"2", "age":22, "name":"name2"}} ],…

VIEW QUESTION

Mongodb – How to remove double quotes inside double quotes in string field?

Currently a document looks like this: { "Post": "this is a post", "_id": ObjectId("630f3c32c1a580642a9ff4a0"), "iframe": ""https:/www.youtube.com/embed/RzVvThhjAKw"", "slug": "this-is-a-title", "title": "This is a title" } But I want it like this: { "Post": "this is a post", "_id": ObjectId("630f3c32c1a580642a9ff4a0"), "iframe": "https:/www.youtube.com/embed/RzVvThhjAKw",…

VIEW QUESTION

MongoDB – How to set the value of a field if it doesn't exist and remain the field if it is already presented in a document

So assume I have a document as shown below: { "_id" : ObjectId("6336d94e0330f5d48e44fb0f"), "systemId" : "5124301", "userId" : "9876543210", "tempId" : "123456da87sdafasdf", "updatedAt" : ISODate("2022-09-30T12:01:11.714+0000"), "receivedAt" : ISODate("2022-04-10T23:15:08.145+0000"), } Now I already have a tempId assigned to the doc and…

VIEW QUESTION
Back To Top
Search