Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

JavaScript MongoDB, replaceOne and using ObjectId

malc_b

Coder
Working on a little project that has me using a number of thing for the first time. One of these is Mongo. Looking to replace a document in a collection by using the Mongo assigned Id. Problem is that I don't ever seem to get a matched record no matter what I do despite the fact the ID exists. The code I've got so far is:

Code:
 database.collection("pid").replaceOne(
    {_id : req.body.id},
    req.body,
    {}
  )

database is defined correctly and it has no problems finding it or the collection. The req.body.id is just the string for the id (ie 62976f1c4dd4127c772e27cd) not the whole ObjectId part of it. I've tried putting together a full string and a query string but each time no match. Seeing as I've been at this waaaaay too long already I was hoping somone may be able to help. Thanks.
 
Back
Top Bottom