Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6009075
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:55:08+00:00 2026-05-23T01:55:08+00:00

I’m concerned about using $pop to remove elements of an array (embedded document) in

  • 0

I’m concerned about using $pop to remove elements of an array (embedded document) in mongodb for 2 main reasons:

  1. I don’t know if the order of the array is static. Is it possible for the array to be returned/stored in a different order?
  2. What if another user removes an index of the a less or equal value before I remove mine? That would cause the wrong data to be removed.

I know I can use $pull, but the issue with that is that I may have to use the entire embeded object for the criterea, I want to be able use somesort of “uniqe enough” (this may be another question entirely) identifier to use when dealing with embeded objects and its position in the array seems to be logical choice.

If it is indeed “unsafe” to use $pop I have thought two possible solutions for a “unique enough” identifier.

  1. Add a new instance of MongoId to each embedded object at time of insertion. The issue with this is now loos the $set’s feature of not inserting a duplicate entry. You would have to check for duplicates before insertion.
  2. json_encode the the new entry, then md5 hash that json string. This may be the best solution because it will ensure that the identifier is unique to that record, but if you try to insert the same entry, it will indeed still be the same so $set will ignore it.

So I guess my question is two part: Is it safe to use $pop when removing items from an array. If not, what is the best practice for adding a unique enough identifiers to embedded documents?

(it may or may not be relevant that I’m using PHP)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T01:55:09+00:00Added an answer on May 23, 2026 at 1:55 am

    For 1, the order of the array won’t change if you manipulate it in the good way.

    For 2, you can use an “Update if current” strategy (optimistic locking): http://www.mongodb.org/display/DOCS/Atomic+Operations#AtomicOperations-%22UpdateifCurrent%22 Add a version field to your document that you will increment at each modification (Doctrine MongoDB ODM can do this for you).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a French site that I want to parse, but am running into
Seemingly simple, but I cannot find anything relevant on the web. What is the
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.