question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to update a mongodb collection

See original GitHub issue

I have the following code:

exports.up = function(db, callback) {
  db.createCollection('table', function() {
    db.insert('table', {
      name: 'micha'
    }, function() {
      db.update('table', {
        name: 'cedric',
        surname: 'camelot'
      }, {
        name: 'micha'
      }, callback);
    });
  });
};

Baiscly what i want is to update specific fields.

What iam getting is:

[ERROR] TypeError: db.update is not a function
<bountysource-plugin> --- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/39613002-how-to-update-a-mongodb-collection?utm_campaign=plugin&utm_content=tracker%2F73887&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F73887&utm_medium=issues&utm_source=github). </bountysource-plugin>

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:2
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
xfgcommented, Jul 27, 2017

@wzrdtales why not simply pass mongodb driver as argument to up/down functions ? In the moment I should use _run that get access to most api of mongodb driver. This is very strange.

1reaction
wzrdtalescommented, May 8, 2017

@BorntraegerMarc Thanks for hitting me up again, things can get lost quite quickly. I often read issues but have no time to immediately answer them. Later they do not pop up again in the notifications though. It is never bad to just ping me up once again, to make me notice 😃

@lampe There is a theoretical implementation already there though. Although it is not available on the public api: https://github.com/db-migrate/mongodb/blob/master/index.js#L432

You could however currently run _run directly with ‘update’ as first argument, see https://github.com/db-migrate/mongodb/blob/master/index.js#L260

Read more comments on GitHub >

github_iconTop Results From Across the Web

db.collection.update() — MongoDB Manual
By default, the db.collection.update() method updates a single document. Include the option multi: true to update all documents that match the query ...
Read more >
MongoDB - Update Document - Tutorialspoint
MongoDB's update () and save() methods are used to update document into a collection. The update() method updates the values in the existing...
Read more >
MongoDB Update() Document with Example - Guru99
MongoDB provides the update() command to update the documents of a collection. To update only the documents you want to update, ...
Read more >
MongoDB Update Document with Examples - Simplilearn
To update a document in MongoDB, we use the update() method. The update() method refreshes the values in a MongoDB collection's existing ...
Read more >
How to update a collection in mongodb - Stack Overflow
4 · db.collection ; 1 · db.mycollection ; 0 · db.<collection_name>.update ; -2 · db.<collection_name>.update ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found