1

Suppose I have a collection in MongoDB with the following schema:

{
    "_id": ObjectID,
    "Entries": [
        {
            "_id": ObjectID,
            "Content": string
        }
    ]
}

Now I want to edit the "Content" field of an element from the array "Entries" and then move that element to the first index - zero - so that the array is sorted descending by when the elements were last changed. Can this be accomplished in an 'atomic' query that I can put in one db.collection.update?

If not, should I use say a UNIX timestamp and then just sort by that when querying? Is the performance difference noticable?

1 Answer 1

0

If you are using objectId inside your array, then part of this id is a timestamp.

That means you can always determine when field was created. If you need to deal with last update - then timestamp field will solve this problem, as I personally will not relay on array position.

See more about objectID and python here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.