Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

update time of each record in MongoDB

Tags:

php

mongodb

MongoDB's ObjectId has a getTimestamp() method that returns time when the record was inserted. Is there a similar method for getting time of last update or should I use a separate column to save this data?

Using PHP (if it matters).

like image 995
johndodo Avatar asked Feb 27 '12 09:02

johndodo


People also ask

How can we update a record in MongoDB?

How can we update a record in MongoDB? To update a record, you need to update on the basis of _id. Let us create a collection with documents − Display all documents from a collection with the help of find () method −

What is the use of updatemany method in MongoDB?

The updateMany () method returns a document that contains multiple fields. The following are the notable ones: The matchedCount stores the number of matched documents. The modifiedCount stores the number of modified documents. To form the update argument, you typically use the $set operator.

What is the difference between filter and update in MongoDB?

The filter is a document that specifies the condition to select the document for update. If you pass an empty document ( {}) into the method, it’ll update all the documents the collection. The update is a document that specifies the updates to apply. The options argument provides some options for updates that won’t be covered in this tutorial.

How do I create a new database in MongoDB?

On the server running MongoDB, type mongo to open up a connection to the database: Once you see the > symbol, you’re ready to create your first database and start adding records.


1 Answers

MongoDB doesn't store the last update so that's something you'll have to store yourself through your application in a separate field.

like image 146
Derick Avatar answered Sep 22 '22 08:09

Derick